[PATCH 2/2] block/curl: HTTP header field names are case insensitive

David Edmondson posted 2 patches 5 years, 11 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
There is a newer version of this series
[PATCH 2/2] block/curl: HTTP header field names are case insensitive
Posted by David Edmondson 5 years, 11 months ago
RFC 7230 section 3.2 indicates that HTTP header field names are case
insensitive.

Signed-off-by: David Edmondson <david.edmondson@oracle.com>
---
 block/curl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/curl.c b/block/curl.c
index 0cf99a4b31b8..4256659cd85b 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -216,11 +216,11 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
     size_t realsize = size * nmemb;
     const char *header = (char *)ptr;
     const char *end = header + realsize;
-    const char *accept_ranges = "Accept-Ranges:";
+    const char *accept_ranges = "accept-ranges:";
     const char *bytes = "bytes";
 
     if (realsize >= strlen(accept_ranges)
-        && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) {
+        && strncasecmp(header, accept_ranges, strlen(accept_ranges)) == 0) {
 
         char *p = strchr(header, ':') + 1;
 
-- 
2.24.1


Re: [PATCH 2/2] block/curl: HTTP header field names are case insensitive
Posted by Philippe Mathieu-Daudé 5 years, 11 months ago
Hi David,

On 2/19/20 2:27 PM, David Edmondson wrote:
> RFC 7230 section 3.2 indicates that HTTP header field names are case
> insensitive.
> 
> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
> ---
>   block/curl.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/block/curl.c b/block/curl.c
> index 0cf99a4b31b8..4256659cd85b 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -216,11 +216,11 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
>       size_t realsize = size * nmemb;
>       const char *header = (char *)ptr;
>       const char *end = header + realsize;
> -    const char *accept_ranges = "Accept-Ranges:";
> +    const char *accept_ranges = "accept-ranges:";
>       const char *bytes = "bytes";
>   
>       if (realsize >= strlen(accept_ranges)
> -        && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) {
> +        && strncasecmp(header, accept_ranges, strlen(accept_ranges)) == 0) {

Can you use g_ascii_strncasecmp() instead?

>   
>           char *p = strchr(header, ':') + 1;
>   
>