#1 2019-02-18 11:14:25

mapes
Member
Registered: 2016-10-30
Posts: 16

TCurlHTTP

Hi,

in SynNodeBinding_HTTPClient
is used TWinHTTP for Windows and TCurlHTTP for Linux

Is it problem to add in
TCurlHTTP.InternalSendRequest
curl.easy_setopt(fHandle,coFollowLocation,1)

to achieve the same behavior?

Because under Windows the result is 200 (auto redirection), under Linux 302 and Location: .... in headers

in case the requested site uses internal redirection

Last edited by mapes (2019-02-18 11:15:29)

Offline

#2 2019-02-18 16:10:16

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: TCurlHTTP

Hm, really default value for WinHttpRequestOption_EnableRedirects is true.

@ab - I agree with @mapes - to have the same behavior for both classes we can add

curl.easy_setopt(fHandle,coFollowLocation,1)

to

TCurlHTTP.InternalCreateRequest

I don`t think it's broke something

Offline

#3 2020-09-06 16:43:10

George
Member
Registered: 2016-04-05
Posts: 140

Re: TCurlHTTP

I found that with TCurlHTTP Basic Authentication does not work.
Server does not receive Authorization header.

{$IFDEF WINDOWS}
  THTTPClient = TWinHTTP;
{$ELSE IF UNIX}
  THTTPClient = TCurlHTTP;
{$ENDIF}

// ...

function TCTR.GetConnector(): THTTPClient;
begin
  Result := THTTPClient.Create(Settings.BackendUrl, Settings.ProxyServer, '', 60 {sec} * 1000, 60 {sec} * 1000, 60 {sec} * 1000, False);
  Result.AuthScheme := THttpRequestAuthentication.wraBasic;
  Result.AuthUserName := 'AuthUserName ';
  Result.AuthPassword := 'AuthPassword ';
end;

Offline

#4 2020-12-12 01:58:50

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: TCurlHTTP

Lazarus + FPC
Cross compiled Win32 -> Linux64 (CentOS)

I'm having strange behavior when making requests to https.

curl.easy_perform(fHandle) raise an exception.

Same application works fine for http requests.
Curl in comand line works fine for http and https requests

I activate coVerbose to see more info:

* About to connect() to httpbin.org port 443 (#0)
*   Trying 52.3.32.149...
* Connected to httpbin.org (52.3.32.149) port 443 (#0)

And after that:

An unhandled exception occurred at $00007F08E251ED00:
EAccessViolation: Access violation
  $00007F08E251ED00

Any tips on what it might be?

It does not seem to be related to a certificate because the Exception would not occur in this case.
And making the request with Curl on the command line is ok.

Offline

#5 2020-12-12 08:09:48

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: TCurlHTTP

If this is on CentOS 7 then a stock version of libcurl 7.29 IS  too old.
I upgrade libcurl to latest and this solves a HTTPS problems. The reason of AV is unknown for me

Offline

#6 2020-12-12 14:05:50

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: TCurlHTTP

Thanks @mpv

Solved by upgrading libcurl.

PS: Really weird the AV

Offline

#7 2021-09-13 10:58:44

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: TCurlHTTP

I found TCurlHTTP ignores send and receive timeouts - this cause my server to wait forever in case resource I call has a bugs (a real life situation).
I create a patch what sets CURLOPT_TIMEOUT to SendTimeout + ReceiveTimeout - this is better than hangs in any case - see https://github.com/synopse/mORMot/pull/404
Also I add usage of CURLOPT_TIMEOUT_MS (available since libcurl 7.16.2 - April 11 2007, so exists in all systems)
@ab - I think it will be good to do the same for mORMot2

Last edited by mpv (2021-09-13 10:58:53)

Offline

#8 2021-09-13 15:58:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: TCurlHTTP

Merged, fixed, and propagated to mORMot 2.

Feedback is welcome!

Offline

#9 2021-09-28 08:55:08

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: TCurlHTTP

I can confirm - curl timeouts works as expected - verified on production

Offline

Board footer

Powered by FluxBB