curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

curl follow location method

From: jicea via curl-users <curl-users_at_lists.haxx.se>
Date: Mon, 10 Jul 2023 17:01:20 +0000

Hello,

First of all, hi to everybody and thanks for curl! It's my first mail to the curl mailing list so I'm a bit nervous!
I struggle to understand the HTTP method chosen by curl while following redirection.

If I read the man, :

> When curl follows a redirect and if the request is a POST, it will send the following request with a GET if
> the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send
> the following request using the same unmodified method.

For status code 301, 302 or 303, curl should switch to GET if I send a POST request with a "Location" header.
I want to test it with a simple Flask endpoint, and I got this :

$ curl --version
curl 8.0.1 (aarch64-apple-darwin21.6.0) libcurl/8.0.1 (SecureTransport) OpenSSL/1.1.1t zlib/1.2.11 brotli/1.0.9 zstd/1.5.5 libidn2/2.3.4 libssh2/1.10.0 nghttp2/1.52.0 librtmp/2.3
Release-Date: 2023-03-20
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd
$ curl --verbose --request POST --location 'http://localhost:8000/follow-redirect'
* Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> POST /follow-redirect HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 302 FOUND
< Server: Werkzeug/2.3.3 Python/3.11.3
< Date: Mon, 10 Jul 2023 16:50:15 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 267
< Location: http://localhost:8000/following-redirect
< Server: Flask Server
< Connection: close
<
* Closing connection 0
* Issue another request to this URL: 'http://localhost:8000/following-redirect'
* Hostname localhost was found in DNS cache
* Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#1)
> POST /following-redirect HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 405 METHOD NOT ALLOWED
< Server: Werkzeug/2.3.3 Python/3.11.3
< Date: Mon, 10 Jul 2023 16:50:15 GMT
< Content-Type: text/html; charset=utf-8
< Allow: GET, OPTIONS, HEAD
< Content-Length: 153
< Server: Flask Server
< Connection: close
<
<!doctype html>
<html lang=en>
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
* Closing connection 1

- The first call is: POST /follow-redirect HTTP/1.1
- The redirection is Location: http://localhost:8000/following-redirect
- The second call is: POST /following-redirect HTTP/1.1

I've certainly missed something but as the status code is 302, I was waiting curl to switch to GET.
My curl version is 8.0.1, I'm on macOS, curl is installed via brew.
Sorry if my mistake is obvious, I try to reread the man but doesn't see what I've missed,

Thanks,

JC






Orange Restricted
____________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-07-10