Http server - Header problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • antimon@gmail.com

    #1

    Http server - Header problem

    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?

  • Vadym Stetsyak

    #2
    Re: Http server - Header problem

    > What would you suggest? Just read once and go or check received data[color=blue]
    > for CRLF+CRLF?[/color]

    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.

    --
    Vadym Stetsyak aka Vadmyst
    Blog about software development, algorithms, network protocols, .NET, programming languages, tips & tricks, coding techniques and more.


    <antimon@gmail. com> wrote in message
    news:1134553315 .917754.54310@f 14g2000cwb.goog legroups.com...[color=blue]
    > 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?
    >[/color]


    Comment

    Working...