Skip to content

Commit

Permalink
Fix HTTP.download stack overflow error on "/" paths (#897)
Browse files Browse the repository at this point in the history
* Fix StackOverflow error as reported in #896

* Fix body summary showing for Dict/NamedTuple bodies

* add test for #896

* Update src/download.jl

Co-authored-by: Frames Catherine White <lyndon.white@invenialabs.co.uk>

* Revert "Update src/download.jl"

This reverts commit 7f82cff.

Co-authored-by: Frames Catherine White <lyndon.white@invenialabs.co.uk>
  • Loading branch information
quinnj and oxinabox committed Aug 17, 2022
1 parent 77017a2 commit 91907fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ function bodysummary(body::Form)
end
return "[Message Body was streamed]"
end
bodysummary(body::Union{Dict, NamedTuple}) = URIs.escapeuri(body)

function compactstartline(m::Message)
b = IOBuffer()
Expand Down
2 changes: 1 addition & 1 deletion src/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end

function try_get_filename_from_request(req)
function file_from_target(t)
t == "" && return nothing
(t == "" || t == "/") && return nothing
f = basename(URI(t).path) # URI(...).path to strip out e.g. query parts
return (f == "" ? file_from_target(dirname(t)) : f)
end
Expand Down
3 changes: 3 additions & 0 deletions test/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ using HTTP
# HTTP.jl#696
file = HTTP.download("https://httpbingo.julialang.org/html?a=b")
@test basename(file) == "html"
# HTTP.jl#896
file = HTTP.download("https://www.cryst.ehu.es/")
@test isfile(file) # just ensure it downloads and doesn't stack overflow
end

@testset "Content-Disposition" begin
Expand Down

0 comments on commit 91907fb

Please sign in to comment.