Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URIs.queryparams overloads #1012

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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