HttpCommon.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * HttpCommon.h
8  *
9  * @author: 2017 - Slavey Karadzhov <slav@attachix.com>
10  *
11  ****/
12 
13 #pragma once
14 
15 #define ENABLE_HTTP_REQUEST_AUTH 1
16 
17 #include "WString.h"
18 #include <Data/WebConstants.h>
19 #include "../Url.h"
21 #include "Data/ObjectMap.h"
22 
23 #ifndef HTTP_MAX_HEADER_SIZE
24 #define HTTP_MAX_HEADER_SIZE (8 * 1024)
25 #endif
26 
27 /* Number of maximum tcp connections to be kept in the pool */
28 #ifndef HTTP_REQUEST_POOL_SIZE
29 #define HTTP_REQUEST_POOL_SIZE 20
30 #endif
31 
32 #include "http-parser/http_parser.h"
33 
42 enum class HttpMethod {
43 #define XX(num, name, string) name = num,
44  HTTP_METHOD_MAP(XX)
45 #undef XX
46 };
47 
48 #define XX(num, name, string) constexpr HttpMethod HTTP_##name = HttpMethod::name;
49 HTTP_METHOD_MAP(XX)
50 #undef XX
51 
55 enum class HttpStatus {
56 #define XX(num, name, string) name = num,
57  HTTP_STATUS_MAP(XX)
58 #undef XX
59 };
60 
61 #define XX(num, name, string) constexpr HttpStatus HTTP_STATUS_##name = HttpStatus::name;
62 HTTP_STATUS_MAP(XX)
63 #undef XX
64 
68 enum class HttpError {
69 #define XX(n, s) n,
70  HTTP_ERRNO_MAP(XX)
71 #undef XX
72 };
73 
74 #define XX(n, s) constexpr HttpError HPE_##n = HttpError::n;
75 HTTP_ERRNO_MAP(XX)
76 #undef XX
77 
78 /* Macro defined using C++ type. Internal http_parser code has own definition */
79 #define HTTP_PARSER_ERRNO(p) HttpError((p)->http_errno)
80 
92 };
93 
95 
100 
108 {
109  return toString(err);
110 }
111 
116 
121 
125 inline String httpGetStatusText(unsigned code)
126 {
127  return toString(HttpStatus(code));
128 }
129 
133 inline String toString(HttpMethod method)
134 {
135  return http_method_str(http_method(method));
136 }
137 
Definition: HttpCommon.h:91
The String class.
Definition: WString.h:136
Definition: HttpCommon.h:90
String httpGetErrorName(HttpError err)
Return a string name of the given error.
Definition: HttpCommon.h:107
Definition: HttpCommon.h:85
String httpGetErrorDescription(HttpError err)
Return a descriptive string for the given error.
HttpError
HTTP error codes.
Definition: HttpCommon.h:68
Definition: HttpCommon.h:89
String httpGetStatusText(unsigned code)
Return a descriptive string for an HTTP status code.
Definition: HttpCommon.h:125
#define SMING_DEPRECATED
Definition: sming_attr.h:30
HttpMethod
Strongly-typed enum which shadows http_method from http_parser library.
Definition: HttpCommon.h:42
XX(num, name, string)
Definition: HttpCommon.h:88
String toString(HttpError err)
Return a descriptive string for the given error.
Definition: HttpCommon.h:87
HttpStatus
HTTP status code.
Definition: HttpCommon.h:55
HttpConnectionState
Identifies current state for an HTTP connection.
Definition: HttpCommon.h:84
Definition: HttpCommon.h:86