xref: /openbsd/usr.sbin/httpd/http.h (revision b7b6a941)
1 /*	$OpenBSD: http.h,v 1.1 2014/07/12 23:34:54 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 _HTTPD_HTTP_H
20 #define _HTTPD_HTTP_H
21 
22 enum httpmethod {
23 	HTTP_METHOD_NONE	= 0,
24 
25 	/* HTTP/1.1, RFC 2616 */
26 	HTTP_METHOD_GET,
27 	HTTP_METHOD_HEAD,
28 	HTTP_METHOD_POST,
29 	HTTP_METHOD_PUT,
30 	HTTP_METHOD_DELETE,
31 	HTTP_METHOD_OPTIONS,
32 	HTTP_METHOD_TRACE,
33 	HTTP_METHOD_CONNECT,
34 
35 	/* WebDAV, RFC 4918 */
36 	HTTP_METHOD_PROPFIND,
37 	HTTP_METHOD_PROPPATCH,
38 	HTTP_METHOD_MKCOL,
39 	HTTP_METHOD_COPY,
40 	HTTP_METHOD_MOVE,
41 	HTTP_METHOD_LOCK,
42 	HTTP_METHOD_UNLOCK,
43 
44 	/* PATCH, RFC 5789 */
45 	HTTP_METHOD_PATCH,
46 
47 	/* Server response (internal value) */
48 	HTTP_METHOD_RESPONSE
49 };
50 
51 struct http_method {
52 	enum httpmethod		 method_id;
53 	const char		*method_name;
54 };
55 #define HTTP_METHODS		{			\
56 	{ HTTP_METHOD_GET,		"GET" },	\
57 	{ HTTP_METHOD_HEAD,		"HEAD" },	\
58 	{ HTTP_METHOD_POST,		"POST" },	\
59 	{ HTTP_METHOD_PUT,		"PUT" },	\
60 	{ HTTP_METHOD_DELETE,		"DELETE" },	\
61 	{ HTTP_METHOD_OPTIONS,		"OPTIONS" },	\
62 	{ HTTP_METHOD_TRACE,		"TRACE" },	\
63 	{ HTTP_METHOD_CONNECT,		"CONNECT" },	\
64 	{ HTTP_METHOD_PROPFIND,		"PROPFIND" },	\
65 	{ HTTP_METHOD_PROPPATCH,	"PROPPATCH" },	\
66 	{ HTTP_METHOD_MKCOL,		"MKCOL" },	\
67 	{ HTTP_METHOD_COPY,		"COPY" },	\
68 	{ HTTP_METHOD_MOVE,		"MOVE" },	\
69 	{ HTTP_METHOD_LOCK,		"LOCK" },	\
70 	{ HTTP_METHOD_UNLOCK,		"UNLOCK" },	\
71 	{ HTTP_METHOD_PATCH,		"PATCH" },	\
72 	{ HTTP_METHOD_NONE,		NULL }		\
73 }
74 
75 struct http_error {
76 	int			 error_code;
77 	const char		*error_name;
78 };
79 #define HTTP_ERRORS		{			\
80 	{ 100,	"Continue" },				\
81 	{ 101,	"Switching Protocols" },		\
82 	{ 200,	"OK" },					\
83 	{ 201,	"Created" },				\
84 	{ 202,	"Accepted" },				\
85 	{ 203,	"Non-Authorative Information" },	\
86 	{ 204,	"No Content" },				\
87 	{ 205,	"Reset Content" },			\
88 	{ 206,	"Partial Content" },			\
89 	{ 300,	"Multiple Choices" },			\
90 	{ 301,	"Moved Permanently" },			\
91 	{ 302,	"Moved Temporarily" },			\
92 	{ 303,	"See Other" },				\
93 	{ 304,	"Not Modified" },			\
94 	{ 307,	"Temporary Redirect" },			\
95 	{ 400,	"Bad Request" },			\
96 	{ 401,	"Unauthorized" },			\
97 	{ 402,	"Payment Required" },			\
98 	{ 403,	"Forbidden" },				\
99 	{ 404,	"Not Found" },				\
100 	{ 405,	"Method Not Allowed" },			\
101 	{ 406,	"Not Acceptable" },			\
102 	{ 407,	"Proxy Authentication Required" },	\
103 	{ 408,	"Request Timeout" },			\
104 	{ 409,	"Conflict" },				\
105 	{ 410,	"Gone" },				\
106 	{ 411,	"Length Required" },			\
107 	{ 412,	"Precondition Failed" },		\
108 	{ 413,	"Request Entity Too Large" },		\
109 	{ 414,	"Request-URL Too Long" },		\
110 	{ 415,	"Unsupported Media Type" },		\
111 	{ 416,	"Requested Range Not Satisfiable" },	\
112 	{ 417,	"Expectation Failed" },			\
113 	{ 500,	"Internal Server Error" },		\
114 	{ 501,	"Not Implemented" },			\
115 	{ 502,	"Bad Gateway" },			\
116 	{ 503,	"Service Unavailable" },		\
117 	{ 504,	"Gateway Timeout" },			\
118 	{ 505,	"HTTP Version Not Supported" },		\
119 	{ 0,	NULL }					\
120 }
121 
122 /* Used during runtime */
123 struct http_descriptor {
124 	struct kv		 http_pathquery;
125 #define http_path		 http_pathquery.kv_key
126 #define http_query		 http_pathquery.kv_value
127 #define http_rescode		 http_pathquery.kv_key
128 #define http_resmesg		 http_pathquery.kv_value
129 
130 	char			*http_version;
131 	enum httpmethod		 http_method;
132 	int			 http_chunked;
133 
134 	/* A tree of headers and attached lists for repeated headers. */
135 	struct kvtree		 http_headers;
136 	struct kv		*http_lastheader;
137 };
138 
139 #endif /* _HTTPD_HTTP_H */
140