Re: [twsocket] Support for HEAD in HTTP server component
Arno Garrels wrote: > Feb 07, 2012 V7.44 Arno - The HEAD method *MUST NOT* return a message-body in > the response. Do not skip compression on HEAD requests, we > need to send the correct size. Method SendDocument > simplified and added two overloads. AnswerStreamAcceptRange > got an overload too. Your fix has worked well in my tests so far. Thanks! Regards, Tobias -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Support for HEAD in HTTP server component
Arno Garrels wrote: > Tobias Rapp wrote: >> Using a variable on object level seems like a better approach than my >> proposal of adding a SendType flag to dozen of functions :-) > > However the patch is buggy, sorry, **don't use it as is**, will check > in a fixed one tonight or tomorrow. Done: SVN rev. #893 Available via SVN now or included in the next nightly snapshot ZIP. http://wiki.overbyte.be/wiki/index.php/ICS_Download Log: Feb 07, 2012 V7.44 Arno - The HEAD method *MUST NOT* return a message-body in the response. Do not skip compression on HEAD requests, we need to send the correct size. Method SendDocument simplified and added two overloads. AnswerStreamAcceptRange got an overload too. Feb 08, 2012 V7.45 Arno - If we receive an unknown method/request we have to close the connection, otherwise we may receive junk data we cannot handle properly. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Support for HEAD in HTTP server component
Tobias Rapp wrote: > Using a variable on object level seems like a better approach than my > proposal of adding a SendType flag to dozen of functions :-) However the patch is buggy, sorry, **don't use it as is**, will check in a fixed one tonight or tomorrow. Found another bug in TBufferedFileStream with XE2 that has to be fixed first. In the XE2 RTL file handle type changed from Integer to THandle, OverbyteIcsUtils.pas needs to be changed as well. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Support for HEAD in HTTP server component
Using a variable on object level seems like a better approach than my proposal of adding a SendType flag to dozen of functions :-) The following lines may cause problems for file streams opened in read/write mode, I guess, because it will truncate the file: > @@ -2865,6 +2881,8 @@ > if FServer.PersistentHeader <> '' then > PutStringInSendBuffer (FServer.PersistentHeader); { V7.29 } > PutStringInSendBuffer(#13#10); > +if FSendType = httpSendHead then{ V7.44 } > +FDocStream.Size := 0; { V7.44 } > SendStream; > end; > @@ -2992,6 +3021,8 @@ > PutStringInSendBuffer (FServer.PersistentHeader); { V7.29 } > PutStringInSendBuffer(GetKeepAliveHdrLines); > PutStringInSendBuffer(#13#10); > +if FSendType = httpSendHead then{ V7.44 } > +FDocStream.Size := 0; { V7.44 } > SendStream; > end; Regards, Tobias -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Support for HEAD in HTTP server component
Tobias Rapp wrote: > Hi, > > I am currently debugging some problems in my application using the > THttpServer/THttpConnection components regarding the support for HEAD > requests. As far as I understand the specs no response body should be > returned for HEAD but it seems that THttpConnection does send response > bodies in procedure ProcessPost() in case of 400/404/etc. answers. Indeed it's a mess and buggy. I just looked at the source and this is my SVN patch (a bit lengthy), what do you (all) think?: {code} Index: OverbyteIcsHttpSrv.pas === --- OverbyteIcsHttpSrv.pas (revision 891) +++ OverbyteIcsHttpSrv.pas (working copy) @@ -9,7 +9,7 @@ check for '..\', '.\', drive designation and UNC. Do the check in OnGetDocument and similar event handlers. Creation: Oct 10, 1999 -Version: 7.43 +Version: 7.44 EMail:francois.pie...@overbyte.be http://www.overbyte.be Support: Use the mailing list twsocket@elists.org Follow "support" link at http://www.overbyte.be for subscription. @@ -336,6 +336,11 @@ Feb 04, 2012 V7.43 Tobias Rapp added method AnswerStreamAcceptRange which is similar to AnswerStream however doesn't ignore requested content range. Use this method only for OK responses. +Feb 07, 2012 V7.44 Arno - The HEAD method *MUST NOT* return a message-body in + the response. Do not skip compression on HEAD requests, we + need to send the correct size. Method SendDocument + simplified and added two overloads. AnswerStreamAcceptRange + got an overload too. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} unit OverbyteIcsHttpSrv; @@ -421,8 +426,8 @@ OverbyteIcsWndControl, OverbyteIcsWSocket, OverbyteIcsWSocketS; const -THttpServerVersion = 743; -CopyRight : String = ' THttpServer (c) 1999-2012 F. Piette V7.43 '; +THttpServerVersion = 744; +CopyRight : String = ' THttpServer (c) 1999-2012 F. Piette V7.44 '; CompressMinSize = 5000; { V7.20 only compress responses within a size range, these are defaults only } CompressMaxSize = 500; MinSndBlkSize = 8192 ; { V7.40 } @@ -593,6 +598,7 @@ THttpConnection = class(TBaseHttpConnection) protected FHttpVerNum : Integer; { V1.6 } +FSendType : THttpSendType; { V7.44 } FPostRcvBuf : array [0..1023] of Byte; { V7.30 }{V7.39} FPostCounter : Int64; { V7.30 }{V7.39} {$IFNDEF NO_AUTHENTICATION_SUPPORT} @@ -746,6 +752,8 @@ constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure SendStream; virtual; +procedure SendDocument; overload; virtual; { V7.44 } +procedure SendDocument(const CustomHeaders: String); overload; virtual; { V7.44 } procedure SendDocument(SendType : THttpSendType); overload; virtual; procedure SendDocument(SendType : THttpSendType; const CustomHeaders: String); overload; virtual; { V7.29 } procedure SendHeader(Header : String); virtual; @@ -813,8 +821,12 @@ procedure AnswerStreamAcceptRange( var Flags : THttpGetFlag; const ContType : String; + LastModified : TDateTime = 0); overload; virtual; { V7.44 } +procedure AnswerStreamAcceptRange( + var Flags : THttpGetFlag; + const ContType : String; const Header : String; - LastModified : TDateTime = 0); virtual; { V7.43 } + LastModified : TDateTime = 0); overload; virtual; { V7.43 } procedure AnswerString(var Flags: THttpGetFlag; const Status : String; const ContType : String; @@ -2622,6 +2634,10 @@ OnDataSent := ConnectionDataSent; { V7.19 always need an event after header is sent } { The line we just received is HTTP command, parse it } ParseRequest; +if FMethod = 'HEAD' then{ V7.44 } +FSendType := httpSendHead { V7.44 } +else{ V7.44 } +FSendType := httpSendDoc; { V7.44 } { Next lines will be header lines } FState := hcHeader; FRequestHasContentLength := FALSE; @@ -2865,6 +2881,8 @@ if FServer.PersistentHeader <> '' then PutStringInSendBuffer (FServer.PersistentHeader); { V7.29 } PutStringInSendBuffer(#13#10); +if FSendType = httpSendHead then{ V7.44 } +
Re: [twsocket] Support for HEAD in HTTP server component
I wrote: > [...] As far as I understand the specs no response body should be > returned for HEAD but it seems that THttpConnection does send response > bodies in procedure ProcessPost() in case of 400/404/etc. answers. ^---^ I wanted to say ProcessHead() here. Regards, Tobias -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be