Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add -X option in curl if -L is present and method is POST. #585

Closed
wants to merge 10 commits into from
15 changes: 15 additions & 0 deletions codegens/curl/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ self = module.exports = {
if (request.method === 'HEAD') {
snippet += ` ${form('-I', format)} ${quoteType + url + quoteType}`;
}
else if (request.method === 'POST' &&
webholik marked this conversation as resolved.
Show resolved Hide resolved
redirect &&
request.body &&
(!_.includes(['formdata', 'urlencoded'], request.body.mode) ||
!_.isEmpty(_.get(request.body, `${request.body.mode}.members`)))) {

// Curl documentation says that if -L option is specified
// _and_ the server returns a 301, 302 or 303 response
// _and_ if the original request is a POST
// then curl will do the following request using GET
// Explicity using the -X disables this behaviour. So we are removing -X here
// to choose the default curl behaviour.
// Curl will automatically determine the method due to --data option being present
snippet += ` ${quoteType + url + quoteType}`;
}
else {
snippet += ` ${form('-X', format)} ${request.method} ${quoteType + url + quoteType}`;
}
Expand Down
4 changes: 2 additions & 2 deletions codegens/curl/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('curl convert function', function () {
}

snippetArray = snippet.split(' ');
expect(snippetArray[4][0]).to.equal('\'');
expect(snippetArray[2][0]).to.equal('\'');
});
});

Expand All @@ -74,7 +74,7 @@ describe('curl convert function', function () {
}

snippetArray = snippet.split(' ');
expect(snippetArray[4][0]).to.equal('"');
expect(snippetArray[2][0]).to.equal('"');
});
});

Expand Down
2 changes: 1 addition & 1 deletion npm/ci-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pushd ./codegens/csharp-restsharp &>/dev/null;
sudo apt-get install dotnet-sdk-2.2
dotnet new console -o testProject
pushd ./testProject &>/dev/null;
dotnet add package RestSharp
dotnet add package RestSharp --version 106.15.0
popd &>/dev/null;
popd &>/dev/null;

Expand Down