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

Ability to modify redirect's type (--post301 etc.) #734

Open
deviantony opened this issue Nov 29, 2018 · 3 comments
Open

Ability to modify redirect's type (--post301 etc.) #734

deviantony opened this issue Nov 29, 2018 · 3 comments
Labels
enhancement New feature or enhancement

Comments

@deviantony
Copy link

deviantony commented Nov 29, 2018

I'm using httpie to execute a POST request against my api at myapi.mydomain.com/endpoint:

http POST http://myapi.mydomain.com/endpoint         
HTTP/1.1 301 Moved Permanently
Content-Length: 17
Content-Type: text/plain; charset=utf-8
Date: Thu, 29 Nov 2018 21:17:20 GMT
Location: https://myapi.mydomain.com:443/endpoint

Moved Permanently

Now using follow:

http -F POST http://myapi.mydomain.com/endpoint
HTTP/1.1 405 Method Not Allowed
Content-Length: 0
Date: Thu, 29 Nov 2018 21:18:39 GMT

Seems that the request method is changed to GET, when using curl, the redirect is working fine:

curl -L -X POST http://myapi.mydomain.com/endpoint
{"msg":"hello world"}

Using httpie version 0.9.8

@jkbrzt
Copy link
Member

jkbrzt commented Nov 29, 2018

@deviantony changing to GET is actually the correct behaviour (or at least the expected default behaviour on today's web).

(If you, for example, submit a form on a website, the most likely behaviour is that the server redirects you to another "thank you" page after processing your request to avoid double-submit on reload, etc.)

curl's behaviour with -X POST is different, but it‘s described as having potential "unintended side-effect" in the docs:

The method string you set with -X, --request will be used for all requests, which if you for example use -L, --location may cause unintended side-effects when curl doesn't change request method according to the HTTP 30x response codes - and similar.
https://curl.haxx.se/docs/manpage.html#-X

I assume that curl does change the method only when you use -d '' without -X POST.

So httpie's default behaviour looks legit to me. What I think it is missing, though, is something like --data301 (similar to curl's --post301 & co) which would explicitly instruct it to reuse the method and re-send the request data on redirect.

@deviantony
Copy link
Author

Thanks for the detailed explanation.

I was exactly looking at the equivalent of curl's --post301 option in a machine to machine HTTP communication context.

@ibnesayeed
Copy link

As per the specs, in order for the server to instruct the client to repeat the request on a redirected location with the original HTTP method it should return 307 or 308. I did not test to see if the httpie respects these status codes appropriately.

@isidentical isidentical added the enhancement New feature or enhancement label Dec 28, 2021
@isidentical isidentical changed the title -F changes the original request method after following redirect Ability to modify redirect's type (--post301 etc.) Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants