rfc 7230 mandates that a "204 No Content" http status must not come with a
authorbenno <benno@openbsd.org>
Mon, 27 Nov 2017 16:25:50 +0000 (16:25 +0000)
committerbenno <benno@openbsd.org>
Mon, 27 Nov 2017 16:25:50 +0000 (16:25 +0000)
Content-Lenght Header. Of course some servers still so it and send
Content-Lenght: 0. Adjust accordingly.
ok claudio@

usr.sbin/relayd/relay_http.c

index 847737d..cf493f8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: relay_http.c,v 1.69 2017/11/27 03:19:58 claudio Exp $ */
+/*     $OpenBSD: relay_http.c,v 1.70 2017/11/27 16:25:50 benno Exp $   */
 
 /*
  * Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -327,19 +327,6 @@ relay_read_http(struct bufferevent *bev, void *arg)
                                relay_abort_http(con, 400, "malformed", 0);
                                goto abort;
                        }
-                       /*
-                        * response with a status code of 1xx
-                        * (Informational) or 204 (No Content) MUST
-                        * not have a Content-Length (rfc 7230 3.3.3)
-                        */
-                       if (desc->http_method == HTTP_METHOD_RESPONSE && (
-                           ((desc->http_status >= 100 &&
-                           desc->http_status < 200) ||
-                           desc->http_status == 204))) {
-                               relay_abort_http(con, 500,
-                                   "Internal Server Error", 0);
-                               goto abort;
-                       }
                        /*
                         * Need to read data from the client after the
                         * HTTP header.
@@ -352,6 +339,23 @@ relay_read_http(struct bufferevent *bev, void *arg)
                                relay_abort_http(con, 500, errstr, 0);
                                goto abort;
                        }
+                       /*
+                        * response with a status code of 1xx
+                        * (Informational) or 204 (No Content) MUST
+                        * not have a Content-Length (rfc 7230 3.3.3)
+                        * Instead we check for value != 0 because there are
+                        * servers that do not follow the rfc and send
+                        * Content-Length: 0.
+                        */
+                       if (desc->http_method == HTTP_METHOD_RESPONSE && (
+                           ((desc->http_status >= 100 &&
+                           desc->http_status < 200) ||
+                           desc->http_status == 204)) &&
+                           cre->toread != 0) {
+                               relay_abort_http(con, 502,
+                                   "Bad Gateway", 0);
+                               goto abort;
+                       }
                }
  lookup:
                if (strcasecmp("Transfer-Encoding", key) == 0 &&