curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: HTTP redirect to HTTPS stops

From: Dave S <snidely.too_at_gmail.com>
Date: Wed, 22 Mar 2017 17:27:24 -0700

On Tue, Mar 21, 2017 at 6:53 PM, Ray Satiro via curl-library <
curl-library_at_cool.haxx.se> wrote:

> On 3/21/2017 8:47 PM, Dave S wrote:
>
> On Tue, Mar 21, 2017 at 2:54 PM, Ray Satiro via curl-library <
> curl-library_at_cool.haxx.se> wrote:
>
>> On 3/21/2017 4:25 PM, Dave S wrote:
>>
>> I'm way back on 7.29.0, so this may be a stupid question, but ...
>>
>> doing a POST to a service we subscribe to, and using the HTTP: scheme,
>> the server sends a 302 redirecting to the same URI with the scheme changed
>> to HTTPS. The 302 frame also has connection: closed.
>>
>> The return code from curl_easy_perform()is 0, but no data is returned,
>> and tcpdump doesn't show any additional interchange after the ack.
>>
>> Changing my URI string (in source) to use the HTTPS: scheme, the exchange
>> completes normally, but should I have been able to troubleshoot this
>> without using tcpdump? Is a redirect to change scheme not automatically
>> followed?
>>
>>
>> Redirects are not enabled by default. Do you have CURLOPT_FOLLOWLOCATION
>> [1] enabled? Try with this URL:
>> http://httpbin.org/redirect-to?url=https://httpbin.org/get
>>
>> [1]: https://curl.haxx.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html
>>
>>
>>
> My first try gets a response code from curl_easy_perform() of 41,
> necessary data rewind wasn't possible
>
> My POSTFIELDSIZE is 238 (bytes).
>
> This is with version 7.45.0, which I was using before the build system
> maintainer got hands on my makefile. (The BldSys is using 7.35.00 on
> Ubuntu, but Centos 7.2 seems to be stuck on 7.29.00)
>
>
> Ok so it seems there is some data and libcurl tries to POST it, but then
> has to rewind since it is redirected. To support rewind use
> CURLOPT_SEEKFUNCTION [1]. Also note if you POST data and the server replies
> with a 301,2,3 redirect then by default libcurl sends a GET request, as
> noted in the FOLLOWLOCATION doc:
>
> "When following a Location:, the 3xx response code that redirected it also
> dictates which request method it will use in the subsequent request: For
> 301, 302 and 303 responses libcurl will switch method to GET unless
> CURLOPT_POSTREDIR instructs libcurl otherwise. All other 3xx codes will
> make libcurl send the same method again."
>
> I think the easiest way to solve this for you though is just use the
> updated https URL, assuming you can POST data to that URL. You said "same
> scheme" but I assume you meant same resource. Like you request
> http://foo/bar/baz and the server is redirecting you to
> https://foo/bar/baz. I have seen quite a few times as websites transition
> to https they redirect all their http to https, so if that's what's
> happening it should be ok to just switch over.
>
>
> [1]: https://curl.haxx.se/libcurl/c/CURLOPT_SEEKFUNCTION.html
>
>
I had already been looking at
<URL:https://curl.haxx.se/libcurl/c/CURLINFO_REDIRECT_URL.html>
so I used that, and once I figured out how to terminate my loop ( =8-O )
I was successful in handling the redirects.

I think you're right about this being a transition point, so the correct
change was to specify the proper scheme in the first place, but I like the
idea of having the 302's
properly handled as well, so both are headed for production.

The remaining question is ... should I have been able to debug this without
tcpdump? The symptoms I ran into was rcc 0 from curl_easy_perform, and
data buffer empty. Maybe I should have turned on a verbose option?

Sidebar question: 7.45.0 isn't quite so embarrassing as 7.29.0, but if I
try to catch up to the Modern Version (7.53.1) is there a shortcut to use
my previous config information to configure the new build?

Thanks.

Dave
/dps

-- 
test signature -- please apply at front gate on Tuesdays only.

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-03-23