Skip to content

Commit

Permalink
Add URIs.queryparams overloads (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-b1 committed Mar 5, 2023
1 parent 3b7466a commit d87d601
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/test/coverage/Manifest.toml
/test/websockets/reports/*
.idea/*
.vscode
3 changes: 3 additions & 0 deletions src/Messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,7 @@ function statustext(status)
return StatusCodes.statustext(status)
end

URIs.queryparams(r::Request) = URIs.queryparams(URI(r.target))
URIs.queryparams(r::Response) = isnothing(r.request) ? nothing : URIs.queryparams(r.request)

end # module Messages
11 changes: 11 additions & 0 deletions test/messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,15 @@ using JSON
# don't include empty headers in request when writing
@test repr(Request("GET", "/", ["Accept" => ""])) == "Request:\n\"\"\"\nGET / HTTP/1.1\r\n\r\n\"\"\""
end

@testset "queryparams" begin
no_params = Request("GET", "http://google.com")
with_params = Request("GET", "http://google.com?q=123&l=345")

@test HTTP.queryparams(no_params) == Dict{String, String}()
@test HTTP.queryparams(with_params) == Dict("q" => "123", "l" => "345")

@test HTTP.queryparams(Response(200; body="", request=with_params)) == Dict("q" => "123", "l" => "345")
@test isnothing(HTTP.queryparams(Response(200; body="")))
end
end

0 comments on commit d87d601

Please sign in to comment.