4

I am creating a Http request parser. I am getting data in chunks (byte array) and parsing it simultaneously. I want to know the condition of detecting end of http request. The request may or may not contain message body.

Thanks

vijay053
  • 822
  • 3
  • 18
  • 36
  • haven't looked it up, but I think two subsequent line-endings indicate the end of the request – Mene Sep 26 '12 at 11:02
  • 2
    This question has already been answered: http://stackoverflow.com/questions/4824451/detect-end-of-http-request-body – randoms Sep 26 '12 at 11:05
  • 1
    This somewhat begs the question why you're writing your own request parser when .Net has a perfectly good one built in? – PhonicUK Sep 26 '12 at 11:06
  • 1
    @PhonicUK: because it's a great learning experience? – randoms Sep 26 '12 at 11:07
  • 1
    ...and the .net one behaves quite badly under stress? – spender Sep 26 '12 at 11:07
  • 1
    @Randoms, fair enough then =) – PhonicUK Sep 26 '12 at 11:15
  • @PhonicUK: Using .Net parser, how can i create a http request and again get the whole data(http request headers and message body) in form of string or byte array, so that i can send it over my sockets which i am using to send and receive data? – vijay053 Jan 10 '13 at 08:45

1 Answers1

5

Three different ways:

  • content-length header (number of bytes following the headers)

  • chunked encoding (content length unknown at start of request, chunked encoding will indicate when the end is reached)

  • connection closed by server (http "0.9")

svick
  • 236,525
  • 50
  • 385
  • 514
spender
  • 117,338
  • 33
  • 229
  • 351