Skip to content

Commit

Permalink
Don't sidestep main entry method for HTTP.request, fixes JuliaWeb#463.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Nov 5, 2019
1 parent 7bcb6f5 commit 881b62d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/HTTP.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module HTTP

export startwrite, startread, closewrite, closeread, stack, insert, AWS4AuthLayer,
export startwrite, startread, closewrite, closeread, stack, insert, AWS4AuthLayer,
BasicAuthLayer, CanonicalizeLayer, ConnectionPoolLayer, ContentTypeDetectionLayer,
DebugLayer, ExceptionLayer, MessageLayer, RedirectLayer, RetryLayer, StreamLayer,
DebugLayer, ExceptionLayer, MessageLayer, RedirectLayer, RetryLayer, StreamLayer,
TimeoutLayer

const DEBUG_LEVEL = Ref(0)
Expand Down Expand Up @@ -160,7 +160,7 @@ Cookie options
- `cookies::Union{Bool, Dict{String, String}} = false`, enable cookies, or alternatively,
pass a `Dict{String, String}` of name-value pairs to manually pass cookies
- `cookiejar::Dict{String, Set{Cookie}}=default_cookiejar`,
- `cookiejar::Dict{String, Set{Cookie}}=default_cookiejar`,
Canonicalization options
Expand Down Expand Up @@ -303,6 +303,15 @@ HTTP.open("POST", "http://music.com/play") do io
end
```
"""
function request(method, url, h=Header[], b=nobody;
headers=h, body=b, query=nothing, kw...)::Response
uri = URI(url)
if query !== nothing
uri = merge(uri, query=query)
end

return request(HTTP.stack(;kw...), string(method), uri, mkheaders(headers), body; kw...)
end
function request(stack::Type{<:Layer}, method, url, h=Header[], b=nobody;
headers=h, body=b, query=nothing, kw...)::Response
uri = URI(url)
Expand All @@ -313,8 +322,6 @@ function request(stack::Type{<:Layer}, method, url, h=Header[], b=nobody;
return request(stack, string(method), uri, mkheaders(headers), body; kw...)
end

request(a...; kw...)::Response = return request(HTTP.stack(;kw...), a...; kw...)

"""
HTTP.open(method, url, [,headers]) do io
write(io, body)
Expand Down

0 comments on commit 881b62d

Please sign in to comment.