Add empty data param to cURL if no POST request body was given (#6017)
* Add empty data param to cURL if no request body was given Some middleware applications do not allow POST requests without a content-length header. By adding a empty data parameter to the curl command, the content-length header will be set by curl. Besides this it is more obvious to the user that no request body is sent. * use double quotes like the rest of the curl command
This commit is contained in:
@@ -25,6 +25,17 @@ describe("curlify", function() {
|
||||
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"Accept: application/json\" -H \"content-type: application/json\" -d {\"id\":0,\"name\":\"doggie\",\"status\":\"available\"}")
|
||||
})
|
||||
|
||||
it("does add a empty data param if no request body given", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"")
|
||||
})
|
||||
|
||||
it("does not change the case of header in curl", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
@@ -36,7 +47,7 @@ describe("curlify", function() {
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\"")
|
||||
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\" -d \"\"")
|
||||
})
|
||||
|
||||
it("prints a curl statement with an array of query params", function() {
|
||||
@@ -145,7 +156,7 @@ describe("curlify", function() {
|
||||
|
||||
it("should print a curl with formData that extracts array representation with hashIdx", function() {
|
||||
// Note: hashIdx = `_**[]${counter}`
|
||||
// Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle
|
||||
// Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle
|
||||
const req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user