20 #ifndef _SMING_CORE_NETWORK_HTTP_HTTP_HEADERS_H_ 21 #define _SMING_CORE_NETWORK_HTTP_HTTP_HEADERS_H_ 23 #include "Data/CStringArray.h" 39 #define HTTP_HEADER_FIELDNAME_MAP(XX) \ 40 XX(ACCESS_CONTROL_ALLOW_ORIGIN, "Access-Control-Allow-Origin", "") \ 41 XX(AUTHORIZATION, "Authorization", "Basic user agent authentication") \ 42 XX(CC, "Cc", "email field") \ 43 XX(CONNECTION, "Connection", "Indicates sender's desired control options") \ 44 XX(CONTENT_DISPOSITION, "Content-Disposition", "Additional information about how to process response payload") \ 45 XX(CONTENT_ENCODING, "Content-Encoding", "Applied encodings in addition to content type") \ 46 XX(CONTENT_LENGTH, "Content-Length", "Anticipated size for payload when not using transfer encoding") \ 47 XX(CONTENT_TYPE, "Content-Type", \ 48 "Payload media type indicating both data format and intended manner of processing by recipient") \ 49 XX(CONTENT_TRANSFER_ENCODING, "Content-Transfer-Encoding", "Coding method used in a MIME message body part") \ 50 XX(CACHE_CONTROL, "Cache-Control", "Directives for caches along the request/response chain") \ 51 XX(DATE, "Date", "Message originating date/time") \ 53 "Validates resource, such as a file, so recipient can confirm whether it has changed - generally more " \ 54 "reliable than Date") \ 55 XX(FROM, "From", "email address of human user who controls the requesting user agent") \ 57 "Request host and port information for target URI; allows server to service requests for multiple hosts on a " \ 58 "single IP address") \ 59 XX(IF_MATCH, "If-Match", \ 60 "Precondition check using ETag to avoid accidental overwrites when servicing multiple user requests. Ensures " \ 61 "resource entity tag matches before proceeding.") \ 62 XX(IF_MODIFIED_SINCE, "If-Modified-Since", "Precondition check using Date") \ 63 XX(LAST_MODIFIED, "Last-Modified", "Server timestamp indicating date and time resource was last modified") \ 64 XX(LOCATION, "Location", "Used in redirect responses, amongst other places") \ 65 XX(SEC_WEBSOCKET_ACCEPT, "Sec-WebSocket-Accept", "Server response to opening Websocket handshake") \ 66 XX(SEC_WEBSOCKET_VERSION, "Sec-WebSocket-Version", \ 67 "Websocket opening request indicates acceptable protocol version. Can appear more than once.") \ 68 XX(SEC_WEBSOCKET_KEY, "Sec-WebSocket-Key", "Websocket opening request validation key") \ 69 XX(SEC_WEBSOCKET_PROTOCOL, "Sec-WebSocket-Protocol", \ 70 "Websocket opening request indicates supported protocol(s), response contains negotiated protocol(s)") \ 71 XX(SERVER, "Server", "Identifies software handling requests") \ 72 XX(SET_COOKIE, "Set-Cookie", "Server may pass name/value pairs and associated metadata to user agent (client)") \ 73 XX(SUBJECT, "Subject", "email subject line") \ 74 XX(TO, "To", "email intended recipient address") \ 75 XX(TRANSFER_ENCODING, "Transfer-Encoding", "e.g. Chunked, compress, deflate, gzip") \ 76 XX(UPGRADE, "Upgrade", \ 77 "Used to transition from HTTP to some other protocol on the same connection. e.g. Websocket") \ 78 XX(USER_AGENT, "User-Agent", "Information about the user agent originating the request") \ 79 XX(WWW_AUTHENTICATE, "WWW-Authenticate", "Indicates HTTP authentication scheme(s) and applicable parameters") 81 enum HttpHeaderFieldName {
82 HTTP_HEADER_UNKNOWN = 0,
83 #define XX(_tag, _str, _comment) HTTP_HEADER_##_tag, 84 HTTP_HEADER_FIELDNAME_MAP(
XX)
106 String toString(HttpHeaderFieldName name)
const;
115 String toString(HttpHeaderFieldName name,
const String& value)
const 117 return toString(toString(name), value);
127 using HashMap::operator[];
137 if(field == HTTP_HEADER_UNKNOWN) {
151 if(field == HTTP_HEADER_UNKNOWN) {
152 field =
static_cast<HttpHeaderFieldName
>(HTTP_HEADER_CUSTOM + customFieldNames.
count());
153 customFieldNames.
add(name);
165 return toString(keyAt(index), valueAt(index));
168 using HashMap::contains;
170 bool contains(
const String& name)
const 175 using HashMap::remove;
177 void remove(
const String& name)
184 for(
unsigned i = 0; i < headers.count(); i++) {
185 HttpHeaderFieldName fieldName = headers.keyAt(i);
186 auto fieldNameString = headers.toString(fieldName);
187 operator[](fieldNameString) = headers.valueAt(i);
194 setMultiple(headers);
200 customFieldNames.
clear();
204 using HashMap::count;
206 DateTime getLastModifiedDate()
const 225 HttpHeaderFieldName findCustomFieldName(
const String& name)
const;
unsigned count() const
Get quantity of strings in array.
Date and time class.
Definition: DateTime.h:77
Definition: WHashMap.h:35
void clear()
Empty the array.
Definition: CStringArray.h:109
The string class.
Definition: WString.h:104
#define XX(name, str, port)
Common URI scheme strings.
Definition: Url.h:54
bool add(const char *str, unsigned length=0)
Append a new string to the end of the array.
Class to manage a double null-terminated list of strings, such as "one\0two\0three".
Definition: CStringArray.h:33
bool fromHttpDate(const String &httpDate)
Parse a HTTP full date and set time and date.