diff options
-rw-r--r-- | src/daemon/Makefile.am | 1 | ||||
-rw-r--r-- | src/daemon/connection.c | 7 | ||||
-rw-r--r-- | src/daemon/reason_phrase.c | 108 | ||||
-rw-r--r-- | src/daemon/reason_phrase.h | 38 |
4 files changed, 152 insertions, 2 deletions
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index c9b73287..b35b45d7 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am | |||
@@ -15,6 +15,7 @@ libmicrohttpd_la_LDFLAGS = \ | |||
15 | -export-dynamic -version-info 2:0:0 $(retaincommand) | 15 | -export-dynamic -version-info 2:0:0 $(retaincommand) |
16 | libmicrohttpd_la_SOURCES = \ | 16 | libmicrohttpd_la_SOURCES = \ |
17 | connection.c connection.h \ | 17 | connection.c connection.h \ |
18 | reason_phrase.c reason_phrase.h \ | ||
18 | daemon.c \ | 19 | daemon.c \ |
19 | internal.c internal.h \ | 20 | internal.c internal.h \ |
20 | memorypool.c memorypool.h \ | 21 | memorypool.c memorypool.h \ |
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 01163154..7abe0205 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "connection.h" | 30 | #include "connection.h" |
31 | #include "memorypool.h" | 31 | #include "memorypool.h" |
32 | #include "response.h" | 32 | #include "response.h" |
33 | #include "reason_phrase.h" | ||
33 | 34 | ||
34 | /** | 35 | /** |
35 | * Message to transmit when http 1.1 request is received | 36 | * Message to transmit when http 1.1 request is received |
@@ -986,12 +987,14 @@ MHD_build_header_response (struct MHD_Connection *connection) | |||
986 | size_t size; | 987 | size_t size; |
987 | size_t off; | 988 | size_t off; |
988 | struct MHD_HTTP_Header *pos; | 989 | struct MHD_HTTP_Header *pos; |
989 | char code[32]; | 990 | char code[128]; |
990 | char date[128]; | 991 | char date[128]; |
991 | char *data; | 992 | char *data; |
992 | 993 | ||
993 | MHD_add_extra_headers (connection); | 994 | MHD_add_extra_headers (connection); |
994 | SPRINTF (code, "%s %u\r\n", MHD_HTTP_VERSION_1_1, connection->responseCode); | 995 | const char* reason_phrase = MHD_get_reason_phrase_for(connection->responseCode); |
996 | _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, | ||
997 | connection->responseCode, reason_phrase); | ||
995 | off = strlen (code); | 998 | off = strlen (code); |
996 | /* estimate size */ | 999 | /* estimate size */ |
997 | size = off + 2; /* extra \r\n at the end */ | 1000 | size = off + 2; /* extra \r\n at the end */ |
diff --git a/src/daemon/reason_phrase.c b/src/daemon/reason_phrase.c new file mode 100644 index 00000000..27d4d73c --- /dev/null +++ b/src/daemon/reason_phrase.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Lymba | ||
4 | |||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Lesser General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2.1 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Lesser General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Lesser General Public | ||
17 | License along with this library; if not, write to the Free Software | ||
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | |||
20 | */ | ||
21 | |||
22 | /** | ||
23 | * @file reason_phrase.c | ||
24 | * @brief Tables of the string response phrases | ||
25 | * @author Elliot Glaysher | ||
26 | * @author Christian Grothoff (minor code clean up) | ||
27 | */ | ||
28 | |||
29 | #include "reason_phrase.h" | ||
30 | |||
31 | static const char * invalid_hundred[] = { }; | ||
32 | |||
33 | static const char * one_hundred[] = { | ||
34 | "Continue", | ||
35 | "Switching Protocols", | ||
36 | "Processing" | ||
37 | }; | ||
38 | |||
39 | static const char* two_hundred[] = { | ||
40 | "OK", | ||
41 | "Created", | ||
42 | "Accepted", | ||
43 | "Non-Authoritative Information", | ||
44 | "No Content", | ||
45 | "Reset Content", | ||
46 | "Partial Content" | ||
47 | }; | ||
48 | |||
49 | static const char* three_hundred[] = { | ||
50 | "Multiple Choices", | ||
51 | "Moved Permanently", | ||
52 | "Moved Temporarily", | ||
53 | "See Other", | ||
54 | "Not Modified", | ||
55 | "Use Proxy" | ||
56 | }; | ||
57 | |||
58 | static const char* four_hundred[] = { | ||
59 | "Bad Request", | ||
60 | "Unauthorized", | ||
61 | "Payment Required", | ||
62 | "Forbidden", | ||
63 | "Not Found", | ||
64 | "Method Not Allowed", | ||
65 | "Not Acceptable", | ||
66 | "Proxy Authentication Required", | ||
67 | "Request Time-out", | ||
68 | "Conflict", | ||
69 | "Gone", | ||
70 | "Length Required", | ||
71 | "Precondition Failed", | ||
72 | "Request Entity Too Large", | ||
73 | "Request-URI Too Large", | ||
74 | "Unsupported Media Type" | ||
75 | }; | ||
76 | |||
77 | static const char* five_hundred[] = { | ||
78 | "Internal Server Error", | ||
79 | "Bad Gateway", | ||
80 | "Service Unavailable", | ||
81 | "Gateway Time-out", | ||
82 | "HTTP Version not supported" | ||
83 | }; | ||
84 | |||
85 | |||
86 | struct MHD_Reason_Block { | ||
87 | unsigned int max; | ||
88 | const char ** data; | ||
89 | }; | ||
90 | |||
91 | #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m } | ||
92 | |||
93 | static const struct MHD_Reason_Block reasons[] = { | ||
94 | BLOCK(one_hundred), | ||
95 | BLOCK(two_hundred), | ||
96 | BLOCK(three_hundred), | ||
97 | BLOCK(four_hundred), | ||
98 | BLOCK(five_hundred), | ||
99 | }; | ||
100 | |||
101 | const char * | ||
102 | MHD_get_reason_phrase_for(unsigned int code) | ||
103 | { | ||
104 | if ( (code >= 100 && code < 600) && | ||
105 | (reasons[code / 100].max > code % 100) ) | ||
106 | return reasons[code / 100].data[code % 100]; | ||
107 | return "Unknown"; | ||
108 | } | ||
diff --git a/src/daemon/reason_phrase.h b/src/daemon/reason_phrase.h new file mode 100644 index 00000000..b6376a2f --- /dev/null +++ b/src/daemon/reason_phrase.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Lymba | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file reason_phrase.c | ||
22 | * @brief Tables of the string response phrases | ||
23 | * @author Elliot Glaysher | ||
24 | */ | ||
25 | |||
26 | #ifndef REASON_PHRASE_H | ||
27 | #define REASON_PHRASE_H | ||
28 | |||
29 | /** | ||
30 | * Returns the string reason phrase for a response code. | ||
31 | * | ||
32 | * If we don't have a string for a status code, we give the first | ||
33 | * message in that status code class. | ||
34 | */ | ||
35 | const char* | ||
36 | MHD_get_reason_phrase_for(unsigned int code); | ||
37 | |||
38 | #endif | ||