Skip to content

Commit

Permalink
Compat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Jun 24, 2024
1 parent f3b3264 commit 6889b81
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/HTTP2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function Base.show(io::IO, r::Request)
println(io, "HTTP2.Request:")
print_request(io, r)
end
# backwards compat
header(r::Request, key::String) = getheader(r.headers, key)

struct StreamMetrics
send_start_timestamp_ns::Int64
Expand Down
12 changes: 7 additions & 5 deletions src/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ function c_on_setup(conn, error_code, ctx_ptr)
setheader(headers, ":scheme", ctx.request.uri.scheme)
# set authority
setheader(headers, ":authority", ctx.request.uri.host)
else
setheader(headers, "host", ctx.request.uri.host)
end
# setheader(headers, "host", ctx.request.uri.host)

# accept header
if !hasheader(headers, "accept")
setheader(headers, "accept", "*/*")
Expand All @@ -101,9 +103,9 @@ function c_on_setup(conn, error_code, ctx_ptr)
setheader(headers, "user-agent", USER_AGENT[])
end
# accept-encoding
# if ctx.decompress === nothing || ctx.decompress
# setheader(headers, "accept-encoding", "gzip")
# end
if ctx.decompress === nothing || ctx.decompress
setheader(headers, "accept-encoding", "gzip")
end
# basic auth if present
if !isempty(ctx.request.uri.userinfo)
setheader(headers, "authorization", "Basic $(base64encode(ctx.request.uri.userinfo))")
Expand Down Expand Up @@ -532,7 +534,7 @@ macro client(modifier)
options(a...; kw...) = ($__source__; request("OPTIONS", a...; kw...))
# open(f, a...; kw...) = ($__source__; request(a...; iofunction=f, kw...))
function request(method, url, h=HTTP2.Header[], b::HTTP2.RequestBodyTypes=nothing;
allocator=HTTP2.ALLOCATOR[],
allocator=HTTP2.default_aws_allocator(),
headers=h,
query=nothing,
body::HTTP2.RequestBodyTypes=b,
Expand Down
6 changes: 6 additions & 0 deletions src/handlers.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module Handlers

import ..Request

"""
Handler
Expand Down Expand Up @@ -390,3 +394,5 @@ request context as implemented in the [`HTTP.Handlers.cookie_middleware`](@ref)
middleware.
"""
getcookies(req) = Base.get(() -> Cookie[], req.context, :cookies)

end # module Handlers
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function getheader(h, k, d="")
i = findfirst(x -> ascii_lc_isequal(x.first, k), h)
return i === nothing ? d : h[i].second
end
# backwards compat
const header = getheader

function setheader(h, k, v)
i = findfirst(x -> ascii_lc_isequal(x.first, k), h)
Expand Down

0 comments on commit 6889b81

Please sign in to comment.