WebConstants.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  * WebConstants.h
8  *
9  ****/
10 
18 #pragma once
19 
20 #include <WString.h>
21 
26 #define MIME_TYPE_MAP(XX) \
27  /* Type, extension start, Mime type */ \
28  \
29  /* Texts */ \
30  XX(UNKNOWN, "", "") \
31  XX(HTML, "html", "text/html") \
32  XX(TEXT, "txt", "text/plain") \
33  XX(JS, "js", "text/javascript") \
34  XX(CSS, "css", "text/css") \
35  XX(XML, "xml", "text/xml") \
36  XX(JSON, "json", "application/json") \
37  \
38  /* Images */ \
39  XX(JPEG, "jpg", "image/jpeg") \
40  XX(GIF, "gif", "image/gif") \
41  XX(PNG, "png", "image/png") \
42  XX(SVG, "svg", "image/svg+xml") \
43  XX(ICO, "ico", "image/x-icon") \
44  \
45  /* Archives */ \
46  XX(GZIP, "gzip", "application/x-gzip") \
47  XX(ZIP, "zip", "application/zip") \
48  \
49  /* Binary and Form */ \
50  XX(BINARY, "", "application/octet-stream") \
51  XX(FORM_URL_ENCODED, "", "application/x-www-form-urlencoded") \
52  XX(FORM_MULTIPART, "", "multipart/form-data")
53 
54 enum MimeType {
55 #define XX(name, extensionStart, mime) MIME_##name,
57 #undef XX
58 };
59 
60 namespace ContentType
61 {
66 String fromFileExtension(const char* extension);
67 
72 static inline String fromFileExtension(const String& extension)
73 {
74  return fromFileExtension(extension.c_str());
75 }
76 
81 String toString(enum MimeType m);
82 
87 MimeType fromString(const char* str);
88 
93 inline MimeType fromString(const String& str)
94 {
95  return fromString(str.c_str());
96 }
97 
102 String fromFullFileName(const char* fileName);
103 
108 static inline String fromFullFileName(const String& fileName)
109 {
110  return fromFullFileName(fileName.c_str());
111 }
112 
113 }; // namespace ContentType
114 
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:600
#define str(s)
Definition: testrunner.h:124
String fromFullFileName(const char *fileName)
Obtain content type string from file name or path, with extension.
MimeType fromString(const char *str)
Get enumerated value for a MIME type string.
#define XX(name, extensionStart, mime)
Definition: WebConstants.h:55
The String class.
Definition: WString.h:136
String toString(enum MimeType m)
Get textual representation for a MIME type.
Definition: WebConstants.h:60
MimeType
Definition: WebConstants.h:54
#define MIME_TYPE_MAP(XX)
Basic MIME types and file extensions.
Definition: WebConstants.h:26
String fromFileExtension(const char *extension)
Obtain content type string from file extension.