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

Redirect (301) after POST re-reads file #9735

Closed
auselen opened this issue Oct 14, 2022 · 2 comments
Closed

Redirect (301) after POST re-reads file #9735

auselen opened this issue Oct 14, 2022 · 2 comments
Assignees
Labels

Comments

@auselen
Copy link

auselen commented Oct 14, 2022

I did this

Some python3 code to imitate the server I was working with

import sys
from http.server import HTTPServer, BaseHTTPRequestHandler
class Redirect(BaseHTTPRequestHandler):
   def do_POST(self):
       post_data = self.rfile.read(1)
       self.send_response(301)
       self.send_header('Location', 'http://no.no')
       self.end_headers()
HTTPServer(("", 9000), Redirect).serve_forever()

$ python3 server.py

$ curl -v -F content=@<(echo hello) -L localhost:9000
...
curl: (65) Cannot rewind mime/post data

I expected the following

Reading https://everything.curl.dev/http/redirects, I wouldn't expect curl to try to rewind my input file (process substitution) when redirect is just a 301 and switches to GET.

curl/libcurl version

I tried with a local build and some prebuilt binary.

curl 7.86.0-DEV, 7.68.0

operating system

.

@bagder bagder added the HTTP label Oct 14, 2022
@dfandrich
Copy link
Contributor

dfandrich commented Oct 15, 2022 via email

@bagder
Copy link
Member

bagder commented Oct 17, 2022

The problem is that curl considers and performs the rewind already when it sees the Location: header in the response to POST, before it has decided it should switch to GET...

@bagder bagder self-assigned this Nov 21, 2022
bagder added a commit that referenced this issue Nov 22, 2022
This makes a big difference for cases when the second request is not
actually performed (for exampel HTTP respons code 301 converts to GET)
and thererfore the rewind can be avoided. In particular for situations
when that rewind *fails*.

Reported-by: Ali Utku Selen

Fixes #9735
Closes #....
bagder added a commit that referenced this issue Nov 22, 2022
Reproduces #9735 and verifies the subsequent fix. The original issue
uses a pipe that cannot be rewound, but this test case instead sets a
callback without rewind ability to get roughly the same properties but
being a much more portable test.
bagder added a commit that referenced this issue Nov 22, 2022
This makes a big difference for cases when the second request is not
actually performed (for example HTTP response code 301 converts to GET)
and therefore the rewind can be avoided. In particular for situations
when that rewind *fails*.

Reported-by: Ali Utku Selen

Fixes #9735
Closes #....
bagder added a commit that referenced this issue Nov 22, 2022
Reproduces #9735 and verifies the subsequent fix. The original issue
uses a pipe that cannot be rewound, but this test case instead sets a
callback without rewind ability to get roughly the same properties but
being a much more portable test.
bagder added a commit that referenced this issue Nov 22, 2022
This makes a big difference for cases when the second request is not
actually performed (for example HTTP response code 301 converts to GET)
and therefore the rewind can be avoided. In particular for situations
when that rewind *fails*.

Reported-by: Ali Utku Selen

Fixes #9735
Closes #9958
bagder added a commit that referenced this issue Nov 22, 2022
Reproduces #9735 and verifies the subsequent fix. The original issue
uses a pipe that cannot be rewound, but this test case instead sets a
callback without rewind ability to get roughly the same properties but
being a much more portable test.
bagder added a commit that referenced this issue Nov 22, 2022
This makes a big difference for cases when the second request is not
actually performed (for example HTTP response code 301 converts to GET)
and therefore the rewind can be avoided. In particular for situations
when that rewind *fails*.

Reported-by: Ali Utku Selen

Fixes #9735
Closes #9958
bagder added a commit that referenced this issue Nov 22, 2022
Reproduces #9735 and verifies the subsequent fix. The original issue
uses a pipe that cannot be rewound, but this test case instead sets a
callback without rewind ability to get roughly the same properties but
being a much more portable test.
bagder added a commit that referenced this issue Nov 24, 2022
This makes a big difference for cases when the second request is not
actually performed (for example HTTP response code 301 converts to GET)
and therefore the rewind can be avoided. In particular for situations
when that rewind *fails*.

Reported-by: Ali Utku Selen

Fixes #9735
Closes #9958
bagder added a commit that referenced this issue Nov 24, 2022
Reproduces #9735 and verifies the subsequent fix. The original issue
uses a pipe that cannot be rewound, but this test case instead sets a
callback without rewind ability to get roughly the same properties but
being a much more portable test.
@bagder bagder closed this as completed in 1b39731 Nov 25, 2022
bagder added a commit that referenced this issue Nov 25, 2022
Reproduces #9735 and verifies the subsequent fix. The original issue
uses a pipe that cannot be rewound, but this test case instead sets a
callback without rewind ability to get roughly the same properties but
being a much more portable test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants