[sheepdog] [PATCH v2 1/2] sheep/http: add range support for swift insterface

Liu Yuan namei.unix at gmail.com
Mon Jan 20 06:27:18 CET 2014


On Fri, Jan 17, 2014 at 03:24:55PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> In swift spec, "Range: bytes=13-15" in http header means "read the three bytes
> of data after a 13-byte offset". We add this support by parsing http header and
> read specific bytes in range.
> 
> We don't support multi-ranges at present.
> 
> v1-->v2:
> 	1. use req->offset and req->data_length instead of req->range[2]

use scissor lines for this, see 'man git format-patch'

> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  sheep/http/http.c | 32 ++++++++++++++++++++++++++++++++
>  sheep/http/http.h |  1 +
>  sheep/http/kv.c   | 41 ++++++++++++++++++++++++++++++++---------
>  3 files changed, 65 insertions(+), 9 deletions(-)
> 
> diff --git a/sheep/http/http.c b/sheep/http/http.c
> index 165c818..cf2315e 100644
> --- a/sheep/http/http.c
> +++ b/sheep/http/http.c
> @@ -169,10 +169,42 @@ static int request_init_operation(struct http_request *req)
>  	req->uri = FCGX_GetParam("DOCUMENT_URI", env);
>  	if (!req->uri)
>  		return BAD_REQUEST;
> +	p = FCGX_GetParam("HTTP_RANGE", env);
> +	if (p && p[0] != '\0') {
> +		const char prefix[] = "bytes=";
> +		char *left, *right, num[64];
> +		uint64_t max;
> +		left = strstr(p, prefix);
> +		if (!p)
> +			goto invalid_range;
> +		right = strchr(left, '-');
> +		strncpy(num, left + sizeof(prefix) - 1, right - left);
> +		req->offset = strtoll(num, &endp, 10);
> +		if (num == endp)
> +			goto invalid_range;
> +		strcpy(num, right + 1);
> +		/*
> +		 * In swift spec, the second number of RANGE should be included
> +		 * which means [num1, num2], but our common means for read and
> +		 * write data by 'offset' and 'len' is [num1, num2), so we
> +		 * should add 1 to num2.
> +		 */
> +		max = strtoll(num, &endp, 10) + 1;
> +		if (num == endp)
> +			goto invalid_range;
> +		if (max <= req->offset)
> +			goto invalid_range;
> +		req->data_length = max - req->offset;
> +		sd_debug("HTTP_RANGE: %lu %lu", req->offset, max);

We use standard PRIxxx macro to print integer to avoid warnings on 32 bits box

Thanks
Yuan



More information about the sheepdog mailing list