Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,23 @@
end
end

range_match = match(r"bytes=(\d+)-(\d+)" , HTTP.header(req, "Range", ""))
range_match = match(r"^bytes=(\d+)-(\d*)$" , HTTP.header(req, "Range", ""))
is_ranged = !isnothing(range_match)

headers = [
"Content-Type" => content_type,
]
if is_ranged
range = parse.(Int, range_match.captures)
p(s) = isempty(s) ? nothing : parse(Int64, s)
start, stop = p.(range_match.captures)
@assert start isa Int64 # because the regex requires at least one digit
stop = something(stop, binary_length(content) - 1)

Check warning on line 474 in src/server.jl

View check run for this annotation

Codecov / codecov/patch

src/server.jl#L471-L474

Added lines #L471 - L474 were not covered by tests

push!(headers,
"Content-Range" =>
"bytes $(range[1])-$(range[2])/$(binary_length(content))"
"bytes $(start)-$(stop)/$(binary_length(content))"
)
content = @view content[1+range[1]:1+range[2]]
content = @view content[1+start:1+stop]

Check warning on line 480 in src/server.jl

View check run for this annotation

Codecov / codecov/patch

src/server.jl#L480

Added line #L480 was not covered by tests
ret_code = 206
end
if allow_cors
Expand Down
Loading