diff --git a/src/utilities/request.jl b/src/utilities/request.jl index 7c25ca0db..a3215ac04 100644 --- a/src/utilities/request.jl +++ b/src/utilities/request.jl @@ -146,7 +146,7 @@ function _http_request(http_backend::HTTPBackend, request::Request, response_str http_options..., ) - return Response(r, response_stream) + return @mock Response(r, response_stream) catch e # Base.IOError is needed because HTTP.jl can often have errors that aren't # caught and wrapped in an HTTP.IOError diff --git a/test/AWS.jl b/test/AWS.jl index e2e47504b..f8a103820 100644 --- a/test/AWS.jl +++ b/test/AWS.jl @@ -278,7 +278,7 @@ struct TestBackend <: AWS.AbstractBackend param::Int end -function AWS._http_request(backend::TestBackend, request::AWS.Request, response_stream::IO) +function AWS._http_request(backend::TestBackend, ::AWS.Request, ::IO) return backend.param end @@ -290,28 +290,30 @@ end url="https://s3.us-east-1.amazonaws.com/sample-bucket", backend=AWS.HTTPBackend(), ) - apply(Patches._http_options_patch) do + io = IOBuffer() + + apply(Patches._http_options_patches) do # No default options - @test isempty(AWS._http_request(request.backend, request)) + @test isempty(AWS._http_request(request.backend, request, io)) # We can pass HTTP options via the backend custom_backend = AWS.HTTPBackend(Dict(:connection_limit => 5)) @test custom_backend isa AWS.AbstractBackend - @test AWS._http_request(custom_backend, request) == Dict(:connection_limit => 5) + @test AWS._http_request(custom_backend, request, io) == Dict(:connection_limit => 5) # We can pass options per-request request.http_options = Dict(:pipeline_limit => 20) - @test AWS._http_request(request.backend, request) == Dict(:pipeline_limit => 20) - @test AWS._http_request(custom_backend, request) == + @test AWS._http_request(request.backend, request, io) == Dict(:pipeline_limit => 20) + @test AWS._http_request(custom_backend, request, io) == Dict(:pipeline_limit => 20, :connection_limit => 5) # per-request options override backend options: custom_backend = AWS.HTTPBackend(Dict(:pipeline_limit => 5)) - @test AWS._http_request(custom_backend, request) == Dict(:pipeline_limit => 20) + @test AWS._http_request(custom_backend, request, io) == Dict(:pipeline_limit => 20) end request.backend = TestBackend(2) - @test AWS._http_request(request.backend, request) == 2 + @test AWS._http_request(request.backend, request, io) == 2 request = Request(; service="s3", @@ -320,7 +322,7 @@ end url="https://s3.us-east-1.amazonaws.com/sample-bucket", backend=TestBackend(4), ) - @test AWS._http_request(request.backend, request) == 4 + @test AWS._http_request(request.backend, request, io) == 4 # Let's test setting the default backend prev_backend = AWS.DEFAULT_BACKEND[] @@ -332,7 +334,7 @@ end request_method="GET", url="https://s3.us-east-1.amazonaws.com/sample-bucket", ) - @test AWS._http_request(request.backend, request) == 3 + @test AWS._http_request(request.backend, request, io) == 3 finally AWS.DEFAULT_BACKEND[] = prev_backend end diff --git a/test/patch.jl b/test/patch.jl index ab105c421..3dfc94166 100644 --- a/test/patch.jl +++ b/test/patch.jl @@ -118,11 +118,12 @@ end # except `require_ssl_verification` and `response_stream`. This is used to # test which other options are being passed to `HTTP.Request` inside of # `_http_request`. -_http_options_patch = @patch function HTTP.request(args...; kwargs...) - options = Dict(kwargs) - delete!(options, :require_ssl_verification) - delete!(options, :response_stream) - return options -end - -end +_http_options_patches = [ + @patch function HTTP.request(args...; kwargs...) + options = Dict(kwargs) + delete!(options, :require_ssl_verification) + delete!(options, :response_stream) + return options + end + @patch AWS.Response(options, args...) = options +]