Merge branch 'mk/http-backend-content-length'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Sep 2018 17:29:16 +0000 (10:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Sep 2018 17:35:42 +0000 (10:35 -0700)
The earlier attempt barfed when given a CONTENT_LENGTH that is
set to an empty string. RFC 3875 is fairly clear that in this
case we should not read any message body, but we've been reading
through to the EOF in previous versions (which did not even pay
attention to the environment variable), so keep that behaviour for
now in this late update.

* mk/http-backend-content-length:
http-backend: allow empty CONTENT_LENGTH

http-backend.c
t/t5562-http-backend-content-length.sh
index 88c38c834ba479447be8eb64f3bc5331cdb9ed49..458642ef72b879a2f53d6e1f8f192847ed814111 100644 (file)
@@ -353,7 +353,7 @@ static ssize_t get_content_length(void)
        ssize_t val = -1;
        const char *str = getenv("CONTENT_LENGTH");
 
-       if (str && !git_parse_ssize_t(str, &val))
+       if (str && *str && !git_parse_ssize_t(str, &val))
                die("failed to parse CONTENT_LENGTH: %s", str);
        return val;
 }
index 43570ce12004d4fd95c85276cdac8f52627c73d9..f94d01f69e5cb9565540411de2c09df92262b9c3 100755 (executable)
@@ -153,4 +153,15 @@ test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
        grep "fatal:.*CONTENT_LENGTH" err
 '
 
+test_expect_success 'empty CONTENT_LENGTH' '
+       env \
+               QUERY_STRING=/repo.git/HEAD \
+               PATH_TRANSLATED="$PWD"/.git/HEAD \
+               GIT_HTTP_EXPORT_ALL=TRUE \
+               REQUEST_METHOD=GET \
+               CONTENT_LENGTH="" \
+               git http-backend <empty_body >act.out 2>act.err &&
+       verify_http_result "200 OK"
+'
+
 test_done