leo-project / leofs

The LeoFS Storage System

Home Page:https://leo-project.net/leofs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

icez opened this issue · comments

commented

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).

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