Here is what I have in a cgi-bin directory:
cgi-bin> cat test1
#!/bin/sh
echo "Status: 200 OK"
echo "Content-type: text/plain"
echo
echo "Hello world 1"
cgi-bin> cat test2
#!/bin/sh
echo "Status: 200 OK"
echo "Content-type: text/plain"
echo "Location: /cgi-bin/test1"
echo
echo "Hello world 2"
cgi-bin> cat test3
#!/bin/sh
echo "Status: 201 Created"
echo "Content-type: text/plain"
echo "Location: /cgi-bin/test1"
echo
echo "Hello world 3"
And here is what I get when I do a GET against each one:
cgi-bin> curl -i https://localhost/cgi-bin/test1
HTTP/1.1 200 OK
Date: Wed, 20 Nov 2019 15:56:43 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: text/plain
Hello world 1
cgi-bin> curl -i https://localhost/cgi-bin/test2
HTTP/1.1 200 OK
Date: Wed, 20 Nov 2019 15:56:44 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: text/plain
Hello world 1
cgi-bin> curl -i https://localhost/cgi-bin/test3
HTTP/1.1 201 Created
Date: Wed, 20 Nov 2019 15:56:45 GMT
Server: Apache
Location: /cgi-bin/test1
Transfer-Encoding: chunked
Content-Type: text/plain
Hello world 3
Notice that /cgi-bin/test2 ignores the “Hello world 2” body that shell script prints, and instead displays the output of test1
. How can I make it use “Hello world 2” as its response, without changing the Status or Location headers?
Edit: updated curl examples to include HTTP headers. Just noticed /cgi-bin/test2 does not include the Location header in the response either.
2
Answers
In your case, you send a 200 with a Location, which is not compliant. Curl probably assumes it’s a 201, so here’s what’s applied:
Since you’re sending conflicting headers, there’s no way you can ask Curl to handle that in a meaningful manner.
Out of curiosity, why would you even want to do that? The resource should either be a 200, 201 or redirect, not a mix of them. If you want to use the Location header for something else, then you’ll need to send a custom header like
my-custom-location
and treat it accordingly.Works as expected for me: