The content-type string curl hands us comes straight from
the server, and may have odd capitalization. RFC 2616 states
that content-types are case-insensitive. We already handle
this when checking for text/plain (by using strcasecmp), but
do not when checking for a smart-http content-type.

We could simply convert the latter to use strcasecmp, but as
we add more parsing of the header, having it normalized will
simplify our parsing code.

Note that there is one caveat. RFC 2616 notes that the type
itself is case insensitive, as are parameter names. However,
parameter valuse may be case-sensitive, depending on the
individual parameter. In practice, we are OK, though. We
currently only look at the type itself. In the future we
will start looking at charset parameters, but those are also
case-insensitive. And it doesn't seem likely that we would
look at any other parameters.

Signed-off-by: Jeff King <>
I think this is fine. If not, we can either:

  1. Use strcasecmp and friends more consistently when
     parsing/comparing (later bits of the series will need to be

  2. Downcase here in a more context-aware way.

 http.c        | 4 +++-
 remote-curl.c | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/http.c b/http.c
index 94e1afd..cd6c328 100644
--- a/http.c
+++ b/http.c
@@ -957,9 +957,11 @@ static int http_request(const char *url,
        ret = run_one_slot(slot, &results);
-       if (options && options->content_type)
+       if (options && options->content_type) {
                curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE,
+               strbuf_tolower(options->content_type);
+       }
        if (options && options->effective_url)
                curlinfo_strbuf(slot->curl, CURLINFO_EFFECTIVE_URL,
diff --git a/remote-curl.c b/remote-curl.c
index 52c2d96..a5ab977 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -205,7 +205,7 @@ static int show_http_message(struct strbuf *type, struct 
strbuf *msg)
         * TODO should handle "; charset=XXX", and re-encode into
         * logoutputencoding
-       if (strcasecmp(type->buf, "text/plain"))
+       if (strcmp(type->buf, "text/plain"))
                return -1;

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to