Skip to content

Instantly share code, notes, and snippets.

@TobiX
Created November 22, 2012 13:00
Show Gist options
  • Save TobiX/4131070 to your computer and use it in GitHub Desktop.
Save TobiX/4131070 to your computer and use it in GitHub Desktop.
Bugfix for SynCrtSock (SSL/no Content-Length)
--- SynCrtSock.pas.orig 2012-11-21 08:16:54.000000000 +0100
+++ SynCrtSock.pas 2012-11-22 13:43:38.000000000 +0100
@@ -938,6 +938,8 @@
// corresponding to the file (e.g. by calling GetMimeContentType() function
// from SynCommons supplyings the file name)
HTTP_RESP_STATICFILE = '!STATICFILE';
+ // While reading an HTTP response, read it in blocks of this size. 8K for now.
+ HTTP_RESP_BLOCK_SIZE = 8*1024;
/// create a TCrtSocket, returning nil on error
// (usefull to easily catch socket error exception ECrtSocket)
@@ -4028,18 +4030,18 @@
aAcceptEncoding := InternalGetInfo(HTTP_QUERY_ACCEPT_ENCODING);
// retrieve received content (if any)
DataLen := InternalGetInfo32(HTTP_QUERY_CONTENT_LENGTH);
- if DataLen<>0 then begin
- SetLength(OutData,DataLen);
- Read := 0;
- repeat
- Bytes := InternalReadData(OutData,Read);
- if Bytes=0 then begin
- SetLength(OutData,Read);
- break;
- end else
- inc(Read,Bytes);
- until Read=DataLen;
- end;
+ // Read response in blocks of HTTP_RESP_BLOCK_SIZE
+ Read := 0;
+ if DataLen<>0 then
+ SetLength(OutData,DataLen)
+ else
+ SetLength(OutData, HTTP_RESP_BLOCK_SIZE);
+ repeat
+ Bytes := InternalReadData(OutData, Read);
+ inc(Read,Bytes);
+ SetLength(OutData, read + HTTP_RESP_BLOCK_SIZE);
+ until Bytes = 0;
+ SetLength(OutData, read);
// handle incoming answer compression
if OutData<>'' then begin
if aDataEncoding<>'' then
@@ -4153,6 +4155,8 @@
INTERNET_FLAG_RESYNCHRONIZE; // options for a true RESTful request
if FKeepAlive<>0 then
Flags := Flags or INTERNET_FLAG_KEEP_CONNECTION;
+ if fHttps then
+ Flags := Flags or INTERNET_FLAG_SECURE;
FRequest := HttpOpenRequestA(FConnection, Pointer(method), Pointer(aURL), nil,
nil, @ALL_ACCEPT, Flags,0);
if FRequest=nil then
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment