View Issue Details

IDProjectCategoryView StatusLast Update
0023729FPCFCLpublic2013-01-23 12:20
ReportersilvioprogAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version2.7.1Fixed in Version3.0.0 
Summary0023729: TFPHTTPClient: HEAD method.
DescriptionHello,

In Synapse and HttpRequester (Firefox plugin) the HEAD method works fine, but in TFPHTTPClient its very slow to connect and don't return the headers.

Sample to reproduce it in attached.

ps. The console output in "Additional Information".
ps2. The HttpRequester output in picture on attached.

Thank you!
Additional InformationC:\Users\silvioprog\Desktop\fhcbug>project1
Synapse: fast, and return the headers. Time: 00:00:00.
Content:
HTTP/1.1 200 OK
Date: Tue, 22 Jan 2013 22:15:28 GMT
Server: Apache
Last-Modified: Tue, 22 Jan 2013 15:49:33 GMT
ETag: "a9b80af-2fa3-4d3e2861d9d40"
Accept-Ranges: bytes
Content-Length: 12195
Vary: Accept-Encoding
Keep-Alive: timeout=10, max=30
Connection: Keep-Alive
Content-Type: text/html

Time:
00:00:00

FCL: slow, and don't return the headers. Time: 00:00:10.
Content:


Time:
00:00:10
C:\Users\silvioprog\Desktop\fhcbug>
TagsNo tags attached.
Fixed in Revision23504.
FPCOldBugId
FPCTarget
Attached Files
  • fhcbug.zip (1,867 bytes)
  • fhcbug-20130122-2045.zip (1,601 bytes)
  • fphttpclient.pp-20130122-2045.patch (623 bytes)
    Index: packages/fcl-web/src/base/fphttpclient.pp
    ===================================================================
    --- packages/fcl-web/src/base/fphttpclient.pp	(revision 23404)
    +++ packages/fcl-web/src/base/fphttpclient.pp	(working copy)
    @@ -719,6 +719,8 @@
       FResponseStatusCode:=ReadResponseHeaders;
       if not CheckResponseCode(FResponseStatusCode,AllowedResponseCodes) then
         Raise EHTTPClient.CreateFmt(SErrUnexpectedResponse,[ResponseStatusCode]);
    +  if (not Assigned(Stream)) or (FSocket.Size < 1) then
    +    Exit;
       if CompareText(CheckTransferEncoding,'chunked')=0 then
         ReadChunkedResponse
       else
    

Activities

2013-01-22 23:24

 

fhcbug.zip (1,867 bytes)

2013-01-22 23:24

 

silvioprog

2013-01-22 23:30

reporter   ~0065086

So, I changed to "Print(FpHttp.ResponseHeaders.Text, E - B);" and worked fine, but the delay (11 secs) remains.

silvioprog

2013-01-22 23:48

reporter   ~0065087

Patch to try solve it in attached. The new demo to test it too.

ps. After apply the patch, the new log will be:


C:\Users\silvioprog\Desktop\fhcbug>project1.exe
Headers:
Date: Tue, 22 Jan 2013 22:45:01 GMT
Server: Apache
Last-Modified: Tue, 22 Jan 2013 15:49:33 GMT
ETag: "a9b80af-2fa3-4d3e2861d9d40"
Accept-Ranges: bytes
Content-Length: 12195
Vary: Accept-Encoding
Content-Type: text/html

Time:
00:00:00
C:\Users\silvioprog\Desktop\fhcbug>

2013-01-22 23:48

 

fhcbug-20130122-2045.zip (1,601 bytes)

2013-01-22 23:49

 

fphttpclient.pp-20130122-2045.patch (623 bytes)
Index: packages/fcl-web/src/base/fphttpclient.pp
===================================================================
--- packages/fcl-web/src/base/fphttpclient.pp	(revision 23404)
+++ packages/fcl-web/src/base/fphttpclient.pp	(working copy)
@@ -719,6 +719,8 @@
   FResponseStatusCode:=ReadResponseHeaders;
   if not CheckResponseCode(FResponseStatusCode,AllowedResponseCodes) then
     Raise EHTTPClient.CreateFmt(SErrUnexpectedResponse,[ResponseStatusCode]);
+  if (not Assigned(Stream)) or (FSocket.Size < 1) then
+    Exit;
   if CompareText(CheckTransferEncoding,'chunked')=0 then
     ReadChunkedResponse
   else

Michael Van Canneyt

2013-01-23 09:16

administrator   ~0065093

You cannot use size() on a socket. It always returns 0.
So this patch is not correct.

Michael Van Canneyt

2013-01-23 09:40

administrator   ~0065094

Your program contains a bug. You print RequestHeaders.

You should print ResponseHeaders instead.

Michael Van Canneyt

2013-01-23 09:47

administrator   ~0065095

You can speed up the process by adding
connection: close
to the request headers, like this:
    fphttp.RequestHeaders.Add('Connection: Close');
    FpHttp.HTTPMethod('HEAD', URL,
      Dummy, // is Dummy really necessary? So, the HTTP contents is empty to HEAD method.
      [200]);
    E := Now;
    Print(FpHttp.ResponseHeaders.Text, E - B);

I implemented a change so you can leave the stream empty.

Michael Van Canneyt

2013-01-23 09:57

administrator   ~0065096

Consider it fixed.
I have added a HEAD class procedure to simplify things:

  S:=TStringList.Create;
  try
    TFPHTTPClient.Head(URL,S);
    Writeln(S.Text);
  finally
    S.Free;
  end;

silvioprog

2013-01-23 12:14

reporter   ~0065098

Fast and wonderful, friend! :)

Worked like a charm. Thank you!

I'll implement this TODO:

{ ---------------------------------------------------------------------
  Todo:
...
  * Easy calls for POST/DELETE/etc.
  ---------------------------------------------------------------------}

Michael Van Canneyt

2013-01-23 12:20

administrator   ~0065099

Easy post is there already. I updated the TODO. (rev 23505)
If it is the same to you, try to work on https support :-)

Issue History

Date Modified Username Field Change
2013-01-22 23:24 silvioprog New Issue
2013-01-22 23:24 silvioprog File Added: fhcbug.zip
2013-01-22 23:24 silvioprog File Added: HttpRequester_ScreenShot.png
2013-01-22 23:30 silvioprog Note Added: 0065086
2013-01-22 23:48 silvioprog Note Added: 0065087
2013-01-22 23:48 silvioprog File Added: fhcbug-20130122-2045.zip
2013-01-22 23:49 silvioprog File Added: fphttpclient.pp-20130122-2045.patch
2013-01-23 09:16 Michael Van Canneyt Note Added: 0065093
2013-01-23 09:40 Michael Van Canneyt Note Added: 0065094
2013-01-23 09:47 Michael Van Canneyt Note Added: 0065095
2013-01-23 09:57 Michael Van Canneyt Fixed in Revision => 23504.
2013-01-23 09:57 Michael Van Canneyt Status new => resolved
2013-01-23 09:57 Michael Van Canneyt Fixed in Version => 2.7.1
2013-01-23 09:57 Michael Van Canneyt Resolution open => fixed
2013-01-23 09:57 Michael Van Canneyt Assigned To => Michael Van Canneyt
2013-01-23 09:57 Michael Van Canneyt Note Added: 0065096
2013-01-23 09:57 Michael Van Canneyt Target Version => 2.7.1
2013-01-23 12:14 silvioprog Status resolved => closed
2013-01-23 12:14 silvioprog Note Added: 0065098
2013-01-23 12:20 Michael Van Canneyt Note Added: 0065099