Re: [PATCH v2 4/8] http: extract type/subtype portion of content-type
- From
Jeff King <peff@peff.net>
- Date
- May 23, 2014, 20:12 UTC
- Message-ID
- <20140523201245.GE19088@sigill.intra.peff.net>
- In-Reply-To
- <567F86A0-98E4-49AF-81C8-8D9E1AEC3C5E@gmail.com>
On Thu, May 22, 2014 at 03:52:21PM -0700, Kyle J. McKay wrote:
Show 24 quoted lines
> >+static void extract_content_type(struct strbuf *raw, struct strbuf *type)
> >+{
> >+ const char *p;
> >+
> >+ strbuf_reset(type);
> >+ strbuf_grow(type, raw->len);
> >+ for (p = raw->buf; *p; p++) {
> >+ if (isspace(*p))
> >+ continue;
> >+ if (*p == ';')
> >+ break;
> >+ strbuf_addch(type, tolower(*p));
> >+ }
> >+}
> >+
>
> This will parse invalid content types as valid. Probably not important
> since the producer of an invalid content type shouldn't be depending on any
> particular behavior by the consumer of such a type, but I think it warrants
> a note in the comment block, perhaps something like:
>
> * Note that an invalid content-type may be converted to a valid one
>
> or some such.Yeah, that is intentional based on our earlier discussion (this function started as "normalize_content_type" :) ). I think it's not a big deal, but agree it's worth a comment. Like:
diff --git a/http.c b/http.c index 4edf5b9..6bfd093 100644 --- a/http.c +++ b/http.c @@ -911,8 +911,14 @@ static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf) * spaces suppressed, all letters lowercased, and no trailing ";" * or parameters. * + * Note that we will silently remove even invalid whitespace. For + * example, "text / plain" is specifically forbidden by RFC 2616, + * but "text/plain" is the only reasonable output, and this keeps + * our code simple. + * * Example: * "TEXT/PLAIN; charset=utf-8" -> "text/plain" + * "text / plain" -> "text/plain" */ static void extract_content_type(struct strbuf *raw, struct strbuf *type) { -Peff