xref: /openbsd/usr.sbin/httpd/http.h (revision 47dc2a9d)
1 /*	$OpenBSD: http.h,v 1.5 2014/08/03 21:33:27 reyk Exp $	*/
2 
3 /*
4  * Copyright (c) 2012 - 2014 Reyk Floeter <reyk@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _HTTP_H
20 #define _HTTP_H
21 
22 #define HTTP_PORT	80
23 #define HTTPS_PORT	443
24 
25 enum httpmethod {
26 	HTTP_METHOD_NONE	= 0,
27 
28 	/* HTTP/1.1, RFC 2616 */
29 	HTTP_METHOD_GET,
30 	HTTP_METHOD_HEAD,
31 	HTTP_METHOD_POST,
32 	HTTP_METHOD_PUT,
33 	HTTP_METHOD_DELETE,
34 	HTTP_METHOD_OPTIONS,
35 	HTTP_METHOD_TRACE,
36 	HTTP_METHOD_CONNECT,
37 
38 	/* WebDAV, RFC 4918 */
39 	HTTP_METHOD_PROPFIND,
40 	HTTP_METHOD_PROPPATCH,
41 	HTTP_METHOD_MKCOL,
42 	HTTP_METHOD_COPY,
43 	HTTP_METHOD_MOVE,
44 	HTTP_METHOD_LOCK,
45 	HTTP_METHOD_UNLOCK,
46 
47 	/* PATCH, RFC 5789 */
48 	HTTP_METHOD_PATCH,
49 
50 	/* Server response (internal value) */
51 	HTTP_METHOD_RESPONSE
52 };
53 
54 struct http_method {
55 	enum httpmethod		 method_id;
56 	const char		*method_name;
57 };
58 #define HTTP_METHODS		{			\
59 	{ HTTP_METHOD_GET,		"GET" },	\
60 	{ HTTP_METHOD_HEAD,		"HEAD" },	\
61 	{ HTTP_METHOD_POST,		"POST" },	\
62 	{ HTTP_METHOD_PUT,		"PUT" },	\
63 	{ HTTP_METHOD_DELETE,		"DELETE" },	\
64 	{ HTTP_METHOD_OPTIONS,		"OPTIONS" },	\
65 	{ HTTP_METHOD_TRACE,		"TRACE" },	\
66 	{ HTTP_METHOD_CONNECT,		"CONNECT" },	\
67 	{ HTTP_METHOD_PROPFIND,		"PROPFIND" },	\
68 	{ HTTP_METHOD_PROPPATCH,	"PROPPATCH" },	\
69 	{ HTTP_METHOD_MKCOL,		"MKCOL" },	\
70 	{ HTTP_METHOD_COPY,		"COPY" },	\
71 	{ HTTP_METHOD_MOVE,		"MOVE" },	\
72 	{ HTTP_METHOD_LOCK,		"LOCK" },	\
73 	{ HTTP_METHOD_UNLOCK,		"UNLOCK" },	\
74 	{ HTTP_METHOD_PATCH,		"PATCH" },	\
75 	{ HTTP_METHOD_NONE,		NULL }		\
76 }
77 
78 struct http_error {
79 	int			 error_code;
80 	const char		*error_name;
81 };
82 #define HTTP_ERRORS		{			\
83 	{ 100,	"Continue" },				\
84 	{ 101,	"Switching Protocols" },		\
85 	{ 200,	"OK" },					\
86 	{ 201,	"Created" },				\
87 	{ 202,	"Accepted" },				\
88 	{ 203,	"Non-Authorative Information" },	\
89 	{ 204,	"No Content" },				\
90 	{ 205,	"Reset Content" },			\
91 	{ 206,	"Partial Content" },			\
92 	{ 300,	"Multiple Choices" },			\
93 	{ 301,	"Moved Permanently" },			\
94 	{ 302,	"Moved Temporarily" },			\
95 	{ 303,	"See Other" },				\
96 	{ 304,	"Not Modified" },			\
97 	{ 307,	"Temporary Redirect" },			\
98 	{ 400,	"Bad Request" },			\
99 	{ 401,	"Unauthorized" },			\
100 	{ 402,	"Payment Required" },			\
101 	{ 403,	"Forbidden" },				\
102 	{ 404,	"Not Found" },				\
103 	{ 405,	"Method Not Allowed" },			\
104 	{ 406,	"Not Acceptable" },			\
105 	{ 407,	"Proxy Authentication Required" },	\
106 	{ 408,	"Request Timeout" },			\
107 	{ 409,	"Conflict" },				\
108 	{ 410,	"Gone" },				\
109 	{ 411,	"Length Required" },			\
110 	{ 412,	"Precondition Failed" },		\
111 	{ 413,	"Request Entity Too Large" },		\
112 	{ 414,	"Request-URL Too Long" },		\
113 	{ 415,	"Unsupported Media Type" },		\
114 	{ 416,	"Requested Range Not Satisfiable" },	\
115 	{ 417,	"Expectation Failed" },			\
116 	{ 500,	"Internal Server Error" },		\
117 	{ 501,	"Not Implemented" },			\
118 	{ 502,	"Bad Gateway" },			\
119 	{ 503,	"Service Unavailable" },		\
120 	{ 504,	"Gateway Timeout" },			\
121 	{ 505,	"HTTP Version Not Supported" },		\
122 	{ 0,	NULL }					\
123 }
124 
125 struct http_mediatype {
126 	char		*media_name;
127 	char		*media_type;
128 	char		*media_subtype;
129 };
130 /* Some default media types */
131 #define MEDIA_TYPES		{			\
132 	{ "css",	"text",		"css" },	\
133 	{ "html",	"text",		"html" },	\
134 	{ "txt",	"text",		"plain" },	\
135 	{ "gif",	"image",	"gif" },	\
136 	{ "jpeg",	"image",	"jpeg" },	\
137 	{ "jpg",	"image",	"jpeg" },	\
138 	{ "png",	"image",	"png" },	\
139 	{ "js",		"application",	"javascript" },	\
140 	{ NULL }					\
141 }
142 
143 /* Used during runtime */
144 struct http_descriptor {
145 	struct kv		 http_pathquery;
146 	struct kv		 http_matchquery;
147 #define http_path		 http_pathquery.kv_key
148 #define http_query		 http_pathquery.kv_value
149 #define http_rescode		 http_pathquery.kv_key
150 #define http_resmesg		 http_pathquery.kv_value
151 #define query_key		 http_matchquery.kv_key
152 #define query_val		 http_matchquery.kv_value
153 
154 	char			*http_host;
155 	enum httpmethod		 http_method;
156 	int			 http_chunked;
157 	char			*http_version;
158 
159 	/* A tree of headers and attached lists for repeated headers. */
160 	struct kv		*http_lastheader;
161 	struct kvtree		 http_headers;
162 };
163 
164 #endif /* _HTTP_H */
165