dodo  0.0.1
A C++ library to create containerized Linux services
httpfragment.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the dodo library (https://github.com/jmspit/dodo).
3  * Copyright (c) 2019 Jan-Marten Spit.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 /**
20  * @file httpfragment.cpp
21  * Implements the dodo::network::HTTPFragment class.
22  */
23 
24 #include <common/exception.hpp>
25 #include <common/puts.hpp>
27 #include <algorithm>
28 #include <sstream>
29 #include <iostream>
30 
31 #include <common/util.hpp>
32 
33 namespace dodo {
34 
35  namespace network::protocol::http {
36 
38  switch ( error ) {
39  case peOk : return "Ok";
40  case peIncomplete : return "incomplete fragment";
41  case peSystemError : return "system error";
42  case peExpectCRLF : return "malformed CRLF sequence";
43  case peUnFinishedToken : return "malformed token";
44  case peExpectingHeaderColon : return "expecting a ':'";
45  case peInvalidHeaderFieldValue : return "malformed header field";
46  case peInvalidHeaderListEnd : return "invalid header list";
47  case peInvalidMethod : return "invalid request method";
48  case peInvalidHTTPVersion : return "invalid HTTP version";
49  case peInvalidRequestLine : return "invalid request line";
50  case peInvalidContentLength : return "content-length mismatch";
51  case peUnexpectedBody : return "body was given but not allowed";
52  case peInvalidTransferEncoding : return "invalid transfer-encoding header";
53  case peInvalidChunkHex : return "invalid hex chunk length";
54  case peInvalidLastChunk : return "last chunk must have size 0";
55  case peExpectingUnsignedInt : return "expecting an unsigned int";
56  default : return common::Puts() << "unhandled error " << error;
57  }
58  }
59 
60  }
61 
62 }
dodo::network::protocol::http::HTTPFragment::peExpectingUnsignedInt
@ peExpectingUnsignedInt
An unsigned int was expected.
Definition: httpfragment.hpp:68
dodo::network::protocol::http::HTTPFragment::peExpectingHeaderColon
@ peExpectingHeaderColon
A header field name was read, but no colon found after it.
Definition: httpfragment.hpp:57
dodo::network::protocol::http::HTTPFragment::getParseResultAsString
static std::string getParseResultAsString(ParseError error)
Return the string description of a ParseError.
Definition: httpfragment.cpp:37
dodo::network::protocol::http::HTTPFragment::peIncomplete
@ peIncomplete
Not an error, but more data is expected to complete.
Definition: httpfragment.hpp:53
dodo::network::protocol::http::HTTPFragment::peUnFinishedToken
@ peUnFinishedToken
A token is being parsed but is ending erroneously.
Definition: httpfragment.hpp:56
dodo::network::protocol::http::HTTPFragment::peInvalidHeaderListEnd
@ peInvalidHeaderListEnd
A header list is not ending properly.
Definition: httpfragment.hpp:59
puts.hpp
dodo::network::protocol::http::HTTPFragment::peSystemError
@ peSystemError
The parse failed due to system error SocketReadBuffer::getLastError()
Definition: httpfragment.hpp:54
dodo::network::protocol::http::HTTPFragment::ParseError
ParseError
Parse results returned by the parse functions.
Definition: httpfragment.hpp:51
dodo::network::protocol::http::HTTPFragment::peInvalidChunkHex
@ peInvalidChunkHex
The hex chunk size is invalid.
Definition: httpfragment.hpp:66
dodo
A C++ platform interface to lean Linux services tailored for containerized deployment.
Definition: application.hpp:29
dodo::network::protocol::http::HTTPFragment::peInvalidRequestLine
@ peInvalidRequestLine
The request line is invalid.
Definition: httpfragment.hpp:62
dodo::network::protocol::http::HTTPFragment::peInvalidTransferEncoding
@ peInvalidTransferEncoding
The specified transfer-encoding header is invalid.
Definition: httpfragment.hpp:65
dodo::network::protocol::http::HTTPFragment::peUnexpectedBody
@ peUnexpectedBody
A message body is present but should not be there.
Definition: httpfragment.hpp:64
httpfragment.hpp
dodo::network::protocol::http::HTTPFragment::peInvalidLastChunk
@ peInvalidLastChunk
The last chunk does not have size 0.
Definition: httpfragment.hpp:67
dodo::network::protocol::http::HTTPFragment::peInvalidHeaderFieldValue
@ peInvalidHeaderFieldValue
A header field value was being read, but it is invalid.
Definition: httpfragment.hpp:58
dodo::network::protocol::http::HTTPFragment::peInvalidMethod
@ peInvalidMethod
An invalid method was specified in the request line.
Definition: httpfragment.hpp:60
exception.hpp
dodo::network::protocol::http::HTTPFragment::peOk
@ peOk
Ok.
Definition: httpfragment.hpp:52
dodo::common::Puts
Helper class to write strings in stream format, eg.
Definition: puts.hpp:46
dodo::network::protocol::http::HTTPFragment::peExpectCRLF
@ peExpectCRLF
A CR was not followed by an LF.
Definition: httpfragment.hpp:55
dodo::network::protocol::http::HTTPFragment::peInvalidContentLength
@ peInvalidContentLength
The content length does not match the message body size.
Definition: httpfragment.hpp:63
util.hpp
dodo::network::protocol::http::HTTPFragment::peInvalidHTTPVersion
@ peInvalidHTTPVersion
An invalid HTTP version was specified in the request line.
Definition: httpfragment.hpp:61