[Gambas-user] HttpClient not exposing redirect response codes

T Lee Davidson t.lee.davidson at ...626...
Fri Apr 28 20:20:37 CEST 2017


On 04/27/2017 03:01 AM, Benoît Minisini wrote:
> Le 25/04/2017 à 19:12, T Lee Davidson a écrit :
>> I have run into a couple of sites that are responding with 301 (Moved
>> Permanently) and 302 (Moved Temporarily) codes. However, HttpClient.Code
>> yields "0" for both of those sites/codes (and HttpClient.Reason is
>> empty). 200 & 404 codes are reported successfully.
>>
>> Have I missed something in the properties that is preventing proper
>> disclosure of redirect response codes?
>>
>> Or is this a bug?
>>
>> (Project attached.)
>>
>
> I have just tested your project, and I get all the expected answers
> (301, 302, 404 & 200).
>
> libcurl (the library used by gb.net.curl) has a flag to automatically
> follow http redirections, but it is disabled by default.
>
> So I don't understand the result you have. Which version of libcurl do
> you use on your system?
>

Actually, I don't think it is a libcurl issue since the first response header does contain the appropriate text and code.

If I run the example project with slightly different output:

   rMatch = New RegExp(hClient.Headers[0], ".*? (\\d+) (.*)")
   TextArea1.Text = hClient.Headers[0] & "\n"
   TextArea1.Text &= "Parsed header code: " & IIf(rMatch[1], rMatch[1].Text, "No code found.") & "\n"
   TextArea1.Text &= "Parsed header reason: " & IIf(rMatch[2], rMatch[2].Text, "No reason found.") & "\n"
   TextArea1.Text &= "HttpClient.Code: " & hClient.Code & "\n"
   TextArea1.Text &= "HttpClient.Reason: " & hClient.Reason & "\n\n"

For the two problem sites, I get:

HTTP/1.1 301 Moved Permanently
Parsed header code: 301
Parsed header reason: Moved Permanently
HttpClient.Code: 0
HttpClient.Reason:

and

HTTP/1.1 302 Moved Temporarily
Parsed header code: 302
Parsed header reason: Moved Temporarily
HttpClient.Code: 0
HttpClient.Reason:


For the 200 & 404 codes, it works as expected.

Thinking it may be a Charset issue, I made sure to send a "Accept-Charset: utf-8" header - no difference.

I've taken a quick look at CHttpClient.c and found http_parse_header, but I don't understand what "ret = (ret * 10) + (*p - 
'0')", among others(!), does.


---
Lee





More information about the User mailing list