Search code examples
resthttpheaderdelimiter

Http Headers as String: Which delimiter to use?


If I am getting a bunch of HTTP headers as a single string, what is the best delimiter to use to separate each header name/value(s) pair? I have though of using commas but they seem to occur within the value of certain HTTP headers. Is there any character that is not allowed for HTTP headers that I can use ?


Solution

  • One straightforward choice would be to use the same delimiter used by HTTP messages themselves. The grammar for messages can be found in RFC 7230 Section 3:

         HTTP-message   = start-line
                          *( header-field CRLF )
                          CRLF
                          [ message-body ]
    

    where CRLF is defined as a carriage return followed by a line feed.

    So my suggestion is to use that.