Skip to content

Commit

Permalink
fix: avoid setting body for GET requests
Browse files Browse the repository at this point in the history
When making a GET request to certain uplinks, such as https://registry.npmmirror.com, setting the body field can result in a 413 error. Previously, the code was setting the body field for all requests, including GET requests.

This commit fixes the issue by checking the request method and avoiding setting the body field for GET requests. This ensures that GET requests are not affected by the issue and can be made without error.

Fixes verdaccio#3601
  • Loading branch information
melodyVoid committed Feb 21, 2023
1 parent 7752424 commit 07cdf46
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/up-storage.ts
Expand Up @@ -219,7 +219,6 @@ class ProxyStorage implements IProxy {
url: uri,
method: method,
headers: headers,
body: json,
proxy: this.proxy,
encoding: null,
gzip: true,
Expand All @@ -228,6 +227,11 @@ class ProxyStorage implements IProxy {
agentOptions: this.agent_options,
};

// GET requests should not have a body, otherwise the request might fail(return 413 status code)
if (method.toUpperCase() !== 'GET') {
requestOptions.body = json
}

if (this.ca) {
requestOptions = Object.assign({}, requestOptions, {
ca: this.ca,
Expand Down

0 comments on commit 07cdf46

Please sign in to comment.