|
|
60545c |
From aa62596afcc9143aa663bf834d305441cdd4cc70 Mon Sep 17 00:00:00 2001
|
|
|
60545c |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
60545c |
Date: Tue, 19 May 2020 11:15:07 +0100
|
|
|
60545c |
Subject: [PATCH 17/19] curl: Case insensitive check for accept-ranges
|
|
|
60545c |
(RHBZ#1837337).
|
|
|
60545c |
MIME-Version: 1.0
|
|
|
60545c |
Content-Type: text/plain; charset=UTF-8
|
|
|
60545c |
Content-Transfer-Encoding: 8bit
|
|
|
60545c |
|
|
|
60545c |
When accessing an HTTP/2 server we read lowercase headers so the
|
|
|
60545c |
existing test for byte range support did not work. You would see an
|
|
|
60545c |
error like this:
|
|
|
60545c |
|
|
|
60545c |
nbdkit: curl[1]: error: server does not support 'range' (byte range) requests
|
|
|
60545c |
|
|
|
60545c |
This commit copies the bug fix which was recently added to qemu’s
|
|
|
60545c |
block/curl.c.
|
|
|
60545c |
|
|
|
60545c |
qemu commits:
|
|
|
60545c |
|
|
|
60545c |
commit 69032253c33ae1774233c63cedf36d32242a85fc
|
|
|
60545c |
Author: David Edmondson <david.edmondson@oracle.com>
|
|
|
60545c |
Date: Mon Feb 24 10:13:10 2020 +0000
|
|
|
60545c |
|
|
|
60545c |
block/curl: HTTP header field names are case insensitive
|
|
|
60545c |
|
|
|
60545c |
commit 7788a319399f17476ff1dd43164c869e320820a2
|
|
|
60545c |
Author: David Edmondson <david.edmondson@oracle.com>
|
|
|
60545c |
Date: Mon Feb 24 10:13:09 2020 +0000
|
|
|
60545c |
|
|
|
60545c |
block/curl: HTTP header fields allow whitespace around values
|
|
|
60545c |
|
|
|
60545c |
Thanks: David Edmondson, Pino Toscano, Zi Liu
|
|
|
60545c |
(cherry picked from commit c1260ec1f6538831e10f164567b53054a2ec0c2a)
|
|
|
60545c |
---
|
|
|
60545c |
plugins/curl/Makefile.am | 1 +
|
|
|
60545c |
plugins/curl/curl.c | 29 ++++++++++++++++++++++++-----
|
|
|
60545c |
tests/web-server.c | 2 +-
|
|
|
60545c |
3 files changed, 26 insertions(+), 6 deletions(-)
|
|
|
60545c |
|
|
|
60545c |
diff --git a/plugins/curl/Makefile.am b/plugins/curl/Makefile.am
|
|
|
60545c |
index 024ddb6d..3dbe3ca8 100644
|
|
|
60545c |
--- a/plugins/curl/Makefile.am
|
|
|
60545c |
+++ b/plugins/curl/Makefile.am
|
|
|
60545c |
@@ -44,6 +44,7 @@ nbdkit_curl_plugin_la_SOURCES = \
|
|
|
60545c |
|
|
|
60545c |
nbdkit_curl_plugin_la_CPPFLAGS = \
|
|
|
60545c |
-I$(top_srcdir)/include \
|
|
|
60545c |
+ -I$(top_srcdir)/common/include \
|
|
|
60545c |
-I$(top_srcdir)/common/utils \
|
|
|
60545c |
$(NULL)
|
|
|
60545c |
nbdkit_curl_plugin_la_CFLAGS = \
|
|
|
60545c |
diff --git a/plugins/curl/curl.c b/plugins/curl/curl.c
|
|
|
60545c |
index b1693dc0..ac30cbdd 100644
|
|
|
60545c |
--- a/plugins/curl/curl.c
|
|
|
60545c |
+++ b/plugins/curl/curl.c
|
|
|
60545c |
@@ -57,6 +57,7 @@
|
|
|
60545c |
#include <nbdkit-plugin.h>
|
|
|
60545c |
|
|
|
60545c |
#include "cleanup.h"
|
|
|
60545c |
+#include "ascii-ctype.h"
|
|
|
60545c |
|
|
|
60545c |
static const char *url = NULL;
|
|
|
60545c |
static const char *user = NULL;
|
|
|
60545c |
@@ -497,12 +498,30 @@ header_cb (void *ptr, size_t size, size_t nmemb, void *opaque)
|
|
|
60545c |
{
|
|
|
60545c |
struct curl_handle *h = opaque;
|
|
|
60545c |
size_t realsize = size * nmemb;
|
|
|
60545c |
- const char *accept_line = "Accept-Ranges: bytes";
|
|
|
60545c |
- const char *line = ptr;
|
|
|
60545c |
+ const char *header = ptr;
|
|
|
60545c |
+ const char *end = header + realsize;
|
|
|
60545c |
+ const char *accept_ranges = "accept-ranges:";
|
|
|
60545c |
+ const char *bytes = "bytes";
|
|
|
60545c |
|
|
|
60545c |
- if (realsize >= strlen (accept_line) &&
|
|
|
60545c |
- strncmp (line, accept_line, strlen (accept_line)) == 0)
|
|
|
60545c |
- h->accept_range = true;
|
|
|
60545c |
+ if (realsize >= strlen (accept_ranges) &&
|
|
|
60545c |
+ strncasecmp (header, accept_ranges, strlen (accept_ranges)) == 0) {
|
|
|
60545c |
+ const char *p = strchr (header, ':') + 1;
|
|
|
60545c |
+
|
|
|
60545c |
+ /* Skip whitespace between the header name and value. */
|
|
|
60545c |
+ while (p < end && *p && ascii_isspace (*p))
|
|
|
60545c |
+ p++;
|
|
|
60545c |
+
|
|
|
60545c |
+ if (end - p >= strlen (bytes)
|
|
|
60545c |
+ && strncmp (p, bytes, strlen (bytes)) == 0) {
|
|
|
60545c |
+ /* Check that there is nothing but whitespace after the value. */
|
|
|
60545c |
+ p += strlen (bytes);
|
|
|
60545c |
+ while (p < end && *p && ascii_isspace (*p))
|
|
|
60545c |
+ p++;
|
|
|
60545c |
+
|
|
|
60545c |
+ if (p == end || !*p)
|
|
|
60545c |
+ h->accept_range = true;
|
|
|
60545c |
+ }
|
|
|
60545c |
+ }
|
|
|
60545c |
|
|
|
60545c |
return realsize;
|
|
|
60545c |
}
|
|
|
60545c |
diff --git a/tests/web-server.c b/tests/web-server.c
|
|
|
60545c |
index f27ee70d..f9f10917 100644
|
|
|
60545c |
--- a/tests/web-server.c
|
|
|
60545c |
+++ b/tests/web-server.c
|
|
|
60545c |
@@ -235,7 +235,7 @@ handle_request (int s, bool headers_only)
|
|
|
60545c |
const char response1_ok[] = "HTTP/1.1 200 OK\r\n";
|
|
|
60545c |
const char response1_partial[] = "HTTP/1.1 206 Partial Content\r\n";
|
|
|
60545c |
const char response2[] =
|
|
|
60545c |
- "Accept-Ranges: bytes\r\n"
|
|
|
60545c |
+ "Accept-rANGES: bytes\r\n" /* See RHBZ#1837337 */
|
|
|
60545c |
"Connection: keep-alive\r\n"
|
|
|
60545c |
"Content-Type: application/octet-stream\r\n";
|
|
|
60545c |
char response3[64];
|
|
|
60545c |
--
|
|
|
60545c |
2.18.2
|
|
|
60545c |
|