http_request: reset "type" strbuf before adding
authorJeff King <peff@peff.net>
Wed, 6 Feb 2013 10:39:52 +0000 (05:39 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Feb 2013 15:50:56 +0000 (07:50 -0800)
Callers may pass us a strbuf which we use to record the
content-type of the response. However, we simply appended to
it rather than overwriting its contents, meaning that cruft
in the strbuf gave us a bogus type. E.g., the multiple
requests triggered by http_request could yield a type like
"text/plainapplication/x-git-receive-pack-advertisement".

Reported-by: Michael Schubert <mschub@elegosoft.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http.c

diff --git a/http.c b/http.c
index d868d8b3d97cc1a430e1680f2bc5f780b5e66a84..d9d1aad3be468394e39966c0b45e7e101b387b0c 100644 (file)
--- a/http.c
+++ b/http.c
@@ -841,6 +841,7 @@ static int http_request(const char *url, struct strbuf *type,
 
        if (type) {
                char *t;
+               strbuf_reset(type);
                curl_easy_getinfo(slot->curl, CURLINFO_CONTENT_TYPE, &t);
                if (t)
                        strbuf_addstr(type, t);