Parsing HTTP headers

  • Hi,

    I need to send an HTTP "Get" and I'm using CFNetwork CFHTTPMessage to
    do that but I have this problem. My code serves glue code for some
    other platform independent code, the call I need to implement takes
    the headers in one chunk and it needs to return the response headers
    as one chunk. The problem is that the CFHTTPMessage API works
    differently: there is no call to set or get the headers as one chunk,
    instead there is a call to set and get single key-value pairs.

    Is there a way to compose and decompose these headers separately
    (beside writing a parser, of-course)? The only thing I could think of
    is creating an empty CFHTTPMessage and then push the header bytes
    into it but I don't know enough about HTTP to know if this will be
    considered a valid header.

    Any thoughts?

    Eyal Redler
    ------------------------------------------------------------------------
    ------------------------
    "If Uri Geller bends spoons with divine powers, then he's doing it
    the hard way."
    --James Randi
    www.eyalredler.com
  • On 9/20/07, Eyal Redler <eyredler...> wrote:
    > Is there a way to compose and decompose these headers separately
    > (beside writing a parser, of-course)? The only thing I could think of
    > is creating an empty CFHTTPMessage and then push the header bytes
    > into it but I don't know enough about HTTP to know if this will be
    > considered a valid header.

    This is not really rocket science. Simply use
    NSString#componentsSeparatedByString to split the chunk into lines.
    Then loop over over each line to find the first : with
    NSString#rangeOfCharacterFromSet and then split the line into a
    key/value pair, stripped from whitespace.

    S.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today