From bd69dc791246a51b6d82e80e2d156798e0e5a259 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Thu, 26 Nov 2020 20:38:10 -0500 Subject: [PATCH 1/2] Add support for 302 redirects where the `Location:` is a relative location path --- .github/workflows/ci.yml | 1 + src/RedirectRequest.jl | 2 +- test/redirects.jl | 6 ++++++ test/runtests.jl | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/redirects.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f13638166..c35592032 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,7 @@ jobs: ${{ runner.os }}-test-${{ env.cache-name }}- ${{ runner.os }}-test- ${{ runner.os }}- + - run: julia --project -e 'import Pkg; Pkg.add(url = "https://github.com/DilumAluthge/URIs.jl", rev = "dpa/relative-uris")' # TODO: remove this line before merging this pull request - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 diff --git a/src/RedirectRequest.jl b/src/RedirectRequest.jl index 2d087a8b3..928320584 100644 --- a/src/RedirectRequest.jl +++ b/src/RedirectRequest.jl @@ -32,7 +32,7 @@ function request(::Type{RedirectLayer{Next}}, kw = merge(merge(NamedTuple(), kw), (parent = res,)) oldurl = url - url = absuri(location, url) + url = absuri(location, url; effective_request_uri = oldurl) if forwardheaders headers = filter(headers) do h # false return values are filtered out diff --git a/test/redirects.jl b/test/redirects.jl new file mode 100644 index 000000000..6a8664b1b --- /dev/null +++ b/test/redirects.jl @@ -0,0 +1,6 @@ +@testset "redirects.jl" begin + @test HTTP.get("https://en.wikipedia.org/api/rest_v1/page/summary/Potato"; redirect = false).status == 200 + @test HTTP.get("https://en.wikipedia.org/api/rest_v1/page/summary/Potato"; redirect = true).status == 200 + @test HTTP.get("https://en.wikipedia.org/api/rest_v1/page/summary/Potatoes"; redirect = false).status == 302 + @test HTTP.get("https://en.wikipedia.org/api/rest_v1/page/summary/Potatoes"; redirect = true).status == 200 +end diff --git a/test/runtests.jl b/test/runtests.jl index cd8aa1355..838ae90d2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,7 +21,8 @@ include("resources/TestRequest.jl") "async.jl", "aws4.jl", "insert_layers.jl", - "mwe.jl"] + "mwe.jl", + "redirects.jl"] file = joinpath(dir, f) println("Running $file tests...") if isfile(file) From b7b535f12f7728b47bd27d95b352caa2cfe951d0 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Fri, 27 Nov 2020 02:17:06 +0000 Subject: [PATCH 2/2] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c35592032..9dee72e78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: ${{ runner.os }}-test-${{ env.cache-name }}- ${{ runner.os }}-test- ${{ runner.os }}- - - run: julia --project -e 'import Pkg; Pkg.add(url = "https://github.com/DilumAluthge/URIs.jl", rev = "dpa/relative-uris")' # TODO: remove this line before merging this pull request + - run: julia --project -e 'import Pkg; Pkg.add(Pkg.PackageSpec(url = "https://github.com/DilumAluthge/URIs.jl", rev = "dpa/relative-uris"))' # TODO: remove this line before merging this pull request - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1