Http server - Header problem

  • Thread starter Thread starter antimon
  • Start date Start date
A

antimon

Hi,
I need to have a simple http server in one of my applications. It's
just for a little text data so i wanted to write my own.
So i have a listener on port 80 and i'm using async methods to receive
/ send data. My problem is, i found lots of sample web server
applications, all of them just calls socket.read method for 1-4kb data.
And parses the response for headers. Isn't it possible to receive
partial data from socket and break this method? I mean i do telnet
google.com:80 and write my request, server doesn't respond till i send
double newline.
What would you suggest? Just read once and go or check received data
for CRLF+CRLF?
 
What would you suggest? Just read once and go or check received data
for CRLF+CRLF?

No, there is no warranty that one read will bring you whole request.

you have to read until CRLF+CRLF is encountered. But it is not the end. this
approach will be suffice only for GET requests as there is no content
following...
if you issue POST requests then you have to obtain HTTP header ( ends with
double CRLF ) and then find field Content-Length and its value.

Then read until you receive Content-Length bytes of the info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top