Skip to content

Commit

Permalink
makeuri utility
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Jun 13, 2024
1 parent 2bd89dc commit 7b9ca24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/HTTP2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ mutable struct Request
uri_ref = Ref{aws_uri}()
if url isa AbstractString
url_str = String(url) * (query === nothing ? "" : ("?" * URIs.escapeuri(query)))
uri = URI(url_str)
elseif url isa URI
url_str = string(url)
uri = url
else
throw(ArgumentError("url must be an AbstractString or URI"))
end
GC.@preserve url_str begin
url_ref = Ref(aws_byte_cursor(sizeof(url_str), pointer(url_str)))
aws_uri_init_parse(uri_ref, allocator, url_ref)
end
return new(String(method), uri, uri_ref[], something(headers, Header[]), body, ctx)
_uri = uri_ref[]
return new(String(method), makeuri(_uri), _uri, something(headers, Header[]), body, ctx)
end
Request() = new()
end
Expand Down
9 changes: 1 addition & 8 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,7 @@ function c_on_request_header_block_done(stream, header_block, conn_ptr)
uri_ref = Ref{aws_uri}()
aws_uri_init_parse(uri_ref, conn.allocator, url_ref)
u = conn.current_request._uri = uri_ref[]
conn.current_request.uri = URIs.URI(
scheme=str(u.scheme),
userinfo=isempty(str(u.userinfo)) ? URIs.absent : str(u.userinfo),
host=str(u.host_name),
port=u.port == 0 ? URIs.absent : u.port,
path=isempty(str(u.path)) ? URIs.absent : str(u.path),
query=isempty(str(u.query_string)) ? URIs.absent : str(u.query_string),
)
conn.current_request.uri = makeuri(u)
# prep request body
buf = Vector{UInt8}(undef, 0)
conn.current_request.body = writebuf(buf)
Expand Down
11 changes: 11 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ function getport(uri::aws_uri)
end
end

function makeuri(u::aws_uri)
return URIs.URI(
scheme=str(u.scheme),
userinfo=isempty(str(u.userinfo)) ? URIs.absent : str(u.userinfo),
host=str(u.host_name),
port=u.port == 0 ? URIs.absent : u.port,
path=isempty(str(u.path)) ? URIs.absent : str(u.path),
query=isempty(str(u.query_string)) ? URIs.absent : str(u.query_string),
)
end

struct AWSError <: Exception
msg::String
end
Expand Down

0 comments on commit 7b9ca24

Please sign in to comment.