Jump to content
Fr0sT.Brutal

(Not a) Design flaw in OverbyteIcsHttpSrv.THttpConnection.ConnectionDataAvailable

Recommended Posts

Method `OverbyteIcsHttpSrv.THttpConnection.ConnectionDataAvailable` contains following line:

    { We use line mode. We will receive complete lines }
    FRcvdLine := ReceiveStr;

And below it is supposed that server have received HTTP-complete (ending with CRLF) line. But

{ Receive as much data as possible into a string                            }
{ You should avoid this function and use Receive. Using string will be      }
{ much slower because data will be copied several times.                    }
{ ReceiveStr will *NOT* wait for a line to be received. It just read        }
{ already received characters and return them as a string.                  }
function TCustomWSocket.ReceiveStr : String;

so a situation is possible when a chunk of header could be processed incorrectly or ignored. I suppose some kind of buffered line reader should be used.

Edited by Sherlock
Slight title correction

Share this post


Link to post

No, header lines will not be ignored or lost since they all end with CRLF, and a double CRLF at the end of the header.  Headers are small, and need to parsed as strings.

To receive a POST body, that function calls an event where you can accept data using Receive and write it to a stream if expecting a large upload or just process some Json or whatever. 

 

Angus

 

Share this post


Link to post

Yep, false alert, sorry. I was misleaded by that comment above TCustomWSocket.ReceiveStr and didn't notice that TCustomLineWSocket does all the necessary stuff incl. size check.

Share this post


Link to post

I'll edit the title to fit this new situation and to not mislead future generations who might dig this up.

Share this post


Link to post

Nah... that's a bit over the top. And we could not say "Ah, there's the guy that cried Wolf to often" when we see you 😛

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×