2 * Copyright (C) 2011-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
8 * This code implements parsing of HTTP requests.
9 * This code was written by Steve Hanov in 2009, no copyright is claimed.
10 * This code is in the public domain.
11 * Code was taken from http://refactormycode.com/codes/778-an-efficient-http-parser
21 // A class to incrementally parse an HTTP header as it comes in. It
22 // lets you know when it has received all required bytes, as specified
23 // by the content-length header (if present). If there is no content-length,
24 // it will stop reading after the final "\n\r".
29 // HttpParser::status_t status;
32 // // read bytes from socket into buffer, break on error
33 // status = parser.addBytes( buffer, length );
34 // if ( status != HttpParser::Incomplete ) break;
37 // if ( status == HttpParser::Done ) {
38 // // parse fully formed http message.
53 status_t
addBytes( const char* bytes
, unsigned len
);
55 const char* getMethod() const;
56 const char* getUri() const;
57 const char* getQueryString() const;
58 const char* getBody() const;
59 // key should be in lower case when looking up.
60 const char* getValue( const char* key
) const;
61 unsigned getContentLength() const;
65 bool parseRequestLine();
68 unsigned _headerStart
= 0;
69 unsigned _parsedTo
= 0 ;
71 unsigned _keyIndex
= 0;
72 unsigned _valueIndex
= 0;
73 unsigned _contentLength
= 0;
74 unsigned _contentStart
= 0;
75 unsigned _uriIndex
= 0;
77 typedef std::vector
<unsigned> IntArray
;
83 p_request_line_crlf
=2,
84 p_request_line_crlfcr
=3,
92 p_content
=11, // here we are done parsing the header.
93 p_error
=12 // here an error has occurred and the parse failed.
96 status_t _status
= Incomplete
;