Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[leo_gateway] 'Content-Range' not response properly when client request range larger than object size #1187

Open
icez opened this issue Jun 27, 2019 · 1 comment
Assignees

Comments

@icez
Copy link

icez commented Jun 27, 2019

I'm setting up nginx caching in front of Leofs-Gateway and using the slice cache to cache large object. But then I found that the gateway response header contain incorrect Content-Length header. Here's an example:

File: object.bin
ObjectSize: 2481708

Client request:

GET /bucket/object.bin HTTP/1.1
Range: bytes=0-9999999

Leofs Response

HTTP/1.1 206 Partial Content
Content-Range: 0-9999999/2481708

Expected Response

HTTP/1.1 206 Partial Content
Content-Range: 0-2481707/2481708

It seems like LeoFS doesn't change the Range header parameter and thus response with the client request header directly. The code seems to be in the file 'apps/leo_gateway/src/leo_gateway_http_commons.erl' around line 1265 at 'range_to_binary'.

%% @private
%% @doc Convert Range List to Content-Range Format
range_to_binary(List, ObjectSize) ->
    range_to_binary(List, ObjectSize, <<>>).

range_to_binary([], _, Acc) ->
    Acc;
range_to_binary([{Start, infinity}|Rest], OS, Acc) ->
    range_to_binary([{Start, OS - 1}|Rest], OS, Acc);
range_to_binary([{Start, End}|Rest], OS, <<>>) ->
    SB = integer_to_binary(Start),
    EB = integer_to_binary(End),
    range_to_binary(Rest, OS, <<SB/binary, "-", EB/binary>>);
range_to_binary([{Start, End}|Rest], OS, Acc) ->
    SB = integer_to_binary(Start),
    EB = integer_to_binary(End),
    range_to_binary(Rest, OS, <<Acc/binary, ",", SB/binary, "-", EB/binary>>);
range_to_binary([End|Rest], OS, Acc) ->
    range_to_binary([{OS + End, OS - 1}|Rest], OS, Acc).
@yosukehara
Copy link
Member

Understood, I'll fix this issue soon. Thank you for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants