6 Replies Latest reply on Jun 24, 2015 4:44 PM by grga

    HTTP request is split into Header and Body (what code does the splitting?)

    ouzenkov

      Hello Guys,

       

      I am studying the way HTTP server is working (Wiced 3.1.2, NetX_Duo stack)

      There are some findings which I cannot figure out.

      Please, help if you know what is going on.

       

      I have written a simple TCP client in C that can send data to HTTP server.

      I am sending a properly formed HTTP request:

      (I have removed some text for brevity; I am sending a C-type string; BSD socket is used; once connection is established I write buffer to the socket )

      const char buffer[] = \

          "POST /api/settings HTTP/1.1\r\n"

      ...

          "Content-Length: 44\r\n"

          "Connection: keep-alive\r\n"

          "Pragma: no-cache\r\n"

          "Cache-Control: no-cache\r\n"

          "\r\n"

          "{\"action\":\"login\", \"param\":\"password\"}";

       

      On the HTTP server end we receive data with the function: wiced_http_server_get_packet_data ( socket, packet, &request_string, &request_length ); It gets the packet which contains only HTTP Header. And request_string is pointing to the start of the Header.

       

      After that, later on, I use wiced_tcp_stream_read(...) and get the HTTP body (of size Content-Length).

       

      It seems that HTTP request is split into 2 parts. HTTP Header comes in the first packet. HTTP body comes in the next packet.

      I cannot figure out who is doing the splitting of HTTP requests. Who is the middle men?

       

      If I try to modify the first line of header, say, "QQQQ /api/settings HTTP/1.1\r\n", I get the whole message in the first packet (including the body)

       

      Is it Netx_Duo that is looking for HTTP requests and on receiving them splits them into Header  and Body with "\r\n\r\n" delimiter?

      Or is it done somewhere above the tcp network stack and I am missing it? Or is it just magic?

       

      I would be grateful for any help.

       

      Oleg