From 69f99097c10aa31305e0508f0f94daba17425c2d Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Nov 2020 16:03:55 -0600 Subject: [PATCH] Disable checks for streamed request bodies --- Project.toml | 2 +- src/BrokenRecord.jl | 3 ++- src/playback.jl | 9 +++++++-- test/runtests.jl | 18 ++++++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 7e64679..3cf679e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BrokenRecord" uuid = "bdd55f5b-6e67-4da1-a080-6086e55655a0" authors = ["Chris de Graaf and contributors"] -version = "0.1.1" +version = "0.1.2" [deps] BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" diff --git a/src/BrokenRecord.jl b/src/BrokenRecord.jl index 96423a9..5ba9905 100644 --- a/src/BrokenRecord.jl +++ b/src/BrokenRecord.jl @@ -6,7 +6,8 @@ using Core: kwftype using BSON: bson, load using Cassette: Cassette, overdub, prehook, @context -using HTTP: HTTP, Header, URI, header, mkheaders, nobody, request, request_uri +using HTTP: HTTP, Header, URI, body_was_streamed, header, mkheaders, nobody, request, + request_uri using Suppressor: @suppress const FORMAT = v"1" diff --git a/src/playback.jl b/src/playback.jl index b981f8a..b9bb841 100644 --- a/src/playback.jl +++ b/src/playback.jl @@ -47,8 +47,13 @@ after(ctx::PlaybackCtx, path) = parse_query(uri) = isempty(uri.query) ? NoQuery() : Dict(split.(split(uri.query, '&'), '=')) -check_body(request, body) = - request.body == Vector{UInt8}(body) || error("Request body does not match") +function check_body(request, body) + if request.body == body_was_streamed + @warn "Can't verify streamed request body" + else + request.body == Vector{UInt8}(body) || error("Request body does not match") + end +end check_method(request, method) = request.method == method || error("Expected $(request.method) request, got $method") diff --git a/test/runtests.jl b/test/runtests.jl index f1f9261..60614d3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,7 @@ -using Test: @test, @testset, @test_throws +using Test: @test, @testset, @test_logs, @test_throws using BSON: load -using HTTP: HTTP +using HTTP: HTTP, Form using BrokenRecord: FORMAT, configure!, playback @@ -79,4 +79,18 @@ const url = "https://httpbin.org" end @test resp1.body == resp2.body end + + mktempdir() do dir + path = joinpath(dir, "test.bson") + playback(path) do + open(@__FILE__) do f + HTTP.post("$url/post"; body=Form(Dict(:file => f))) + end + end + playback(path) do + open(@__FILE__) do f + @test_logs (:warn, r"streamed") HTTP.post("$url/post"; body=Form(Dict(:file => f))) + end + end + end end