View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001285 | libmicrohttpd | compliance | public | 2007-10-10 10:58 | 2007-10-11 11:06 |
| Reporter | eglaysher | Assigned To | Christian Grothoff | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | fixed | ||
| Product Version | 0.1.0 | ||||
| Summary | 0001285: libmicrohttpd doesn't conformant status lines | ||||
| Description | libmicrohttpd's format string for status lines, "%s %u\r\n" (from MHD_build_header_response) does not technically comply with RFC2068. Here are the grammars excerpted from sections 6.1 and 6.1.1 of the RFC: Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF Reason-Phrase = *<TEXT, excluding CR, LF> We have a 3rd party web client which is raising a grammar error because of the lack of the second space in Status-Line. Attached is a patch that fixes this issue, and also adds the recommended reason phrases to the status line. -- Elliot | ||||
| Tags | No tags attached. | ||||
| Attached Files | libmicrohttpd-reasoncode.patch (6,168 bytes)
Index: libmicrohttpd-0.1.0-old/src/daemon/reason_phrase.h
===================================================================
--- libmicrohttpd-0.1.0-old/src/daemon/reason_phrase.h (revision 0)
+++ libmicrohttpd-0.1.0/src/daemon/reason_phrase.h (revision 0)
@@ -0,0 +1,38 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Lymba
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/**
+ * @file reason_phrase.c
+ * @brief Tables of the string response phrases
+ * @author Elliot Glaysher
+ */
+
+#ifndef REASON_PHRASE_H
+#define REASON_PHRASE_H
+
+/**
+ * Returns the string reason phrase for a response code.
+ *
+ * If we don't have a string for a status code, we give the first
+ * message in that status code class.
+ */
+const char*
+MHD_get_reason_phrase_for(int code);
+
+#endif
Index: libmicrohttpd-0.1.0-old/src/daemon/connection.c
===================================================================
--- libmicrohttpd-0.1.0-old/src/daemon/connection.c (revision 5709)
+++ libmicrohttpd-0.1.0/src/daemon/connection.c (working copy)
@@ -30,6 +30,7 @@
#include "connection.h"
#include "memorypool.h"
#include "response.h"
+#include "reason_phrase.h"
/**
* Message to transmit when http 1.1 request is received
@@ -986,12 +987,14 @@
size_t size;
size_t off;
struct MHD_HTTP_Header *pos;
- char code[32];
+ char code[128];
char date[128];
char *data;
MHD_add_extra_headers (connection);
- SPRINTF (code, "%s %u\r\n", MHD_HTTP_VERSION_1_1, connection->responseCode);
+ const char* reason_phrase = MHD_get_reason_phrase_for(connection->responseCode);
+ _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1,
+ connection->responseCode, reason_phrase);
off = strlen (code);
/* estimate size */
size = off + 2; /* extra \r\n at the end */
Index: libmicrohttpd-0.1.0-old/src/daemon/Makefile.am
===================================================================
--- libmicrohttpd-0.1.0-old/src/daemon/Makefile.am (revision 5709)
+++ libmicrohttpd-0.1.0/src/daemon/Makefile.am (working copy)
@@ -15,6 +15,7 @@
-export-dynamic -version-info 2:0:0 $(retaincommand)
libmicrohttpd_la_SOURCES = \
connection.c connection.h \
+ reason_phrase.c reason_phrase.h \
daemon.c \
internal.c internal.h \
memorypool.c memorypool.h \
Index: libmicrohttpd-0.1.0-old/src/daemon/reason_phrase.c
===================================================================
--- libmicrohttpd-0.1.0-old/src/daemon/reason_phrase.c (revision 0)
+++ libmicrohttpd-0.1.0/src/daemon/reason_phrase.c (revision 0)
@@ -0,0 +1,119 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Lymba
+
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+/**
+ * @file reason_phrase.c
+ * @brief Tables of the string response phrases
+ * @author Elliot Glaysher
+ */
+
+#include "reason_phrase.h"
+
+const char* one_hundred[] = {
+ "Continue",
+ "Switching Protocols",
+ "Processing"
+};
+
+const char* two_hundred[] = {
+ "OK",
+ "Created",
+ "Accepted",
+ "Non-Authoritative Information",
+ "No Content",
+ "Reset Content",
+ "Partial Content"
+};
+
+const char* three_hundred[] = {
+ "Multiple Choices",
+ "Moved Permanently",
+ "Moved Temporarily",
+ "See Other",
+ "Not Modified",
+ "Use Proxy"
+};
+
+const char* four_hundred[] = {
+ "Bad Request",
+ "Unauthorized",
+ "Payment Required",
+ "Forbidden",
+ "Not Found",
+ "Method Not Allowed",
+ "Not Acceptable",
+ "Proxy Authentication Required",
+ "Request Time-out",
+ "Conflict",
+ "Gone",
+ "Length Required",
+ "Precondition Failed",
+ "Request Entity Too Large",
+ "Request-URI Too Large",
+ "Unsupported Media Type"
+};
+
+const char* five_hundred[] = {
+ "Internal Server Error",
+ "Bad Gateway",
+ "Service Unavailable",
+ "Gateway Time-out",
+ "HTTP Version not supported"
+};
+
+#define CORRECT_CODE(code, x) { if(code >= (sizeof(x)/sizeof(x[0]))) code = 0; }
+
+const char*
+MHD_get_reason_phrase_for(int code)
+{
+ if(code >= 100 && code < 200)
+ {
+ code -= 100;
+ CORRECT_CODE(code, one_hundred);
+ return one_hundred[code];
+ }
+ else if(code >= 200 && code < 300)
+ {
+ code -= 200;
+ CORRECT_CODE(code, two_hundred);
+ return two_hundred[code];
+ }
+ else if(code >= 300 && code < 400)
+ {
+ code -= 300;
+ CORRECT_CODE(code, three_hundred);
+ return three_hundred[code];
+ }
+ else if(code >= 400 && code < 500)
+ {
+ code -= 400;
+ CORRECT_CODE(code, four_hundred);
+ return four_hundred[code];
+ }
+ else if(code >= 500 && code < 600)
+ {
+ code -= 500;
+ CORRECT_CODE(code, five_hundred);
+ return five_hundred[code];
+ }
+ else
+ return "Unknown";
+}
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2007-10-10 10:58 | eglaysher | New Issue | |
| 2007-10-10 10:58 | eglaysher | File Added: libmicrohttpd-reasoncode.patch | |
| 2007-10-11 10:07 | Christian Grothoff | Status | new => assigned |
| 2007-10-11 10:07 | Christian Grothoff | Assigned To | => Christian Grothoff |
| 2007-10-11 10:10 | Christian Grothoff | Status | assigned => resolved |
| 2007-10-11 10:10 | Christian Grothoff | Resolution | open => fixed |
| 2007-10-11 10:10 | Christian Grothoff | Note Added: 0003191 | |
| 2007-10-11 11:06 | Christian Grothoff | Status | resolved => closed |