diff --git a/.gitignore b/.gitignore index 57815c53b..9ac1073d7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /test/coverage/Manifest.toml /test/websockets/reports/* .idea/* +.vscode diff --git a/src/Messages.jl b/src/Messages.jl index 57456a111..879a984ee 100644 --- a/src/Messages.jl +++ b/src/Messages.jl @@ -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 diff --git a/test/messages.jl b/test/messages.jl index 67b4cc2ac..fbad5e893 100644 --- a/test/messages.jl +++ b/test/messages.jl @@ -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