Skip to content

Commit

Permalink
Disable checks for streamed request bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG committed Nov 1, 2020
1 parent 7f2138c commit 69f9909
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BrokenRecord"
uuid = "bdd55f5b-6e67-4da1-a080-6086e55655a0"
authors = ["Chris de Graaf <me@cdg.dev> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down
3 changes: 2 additions & 1 deletion src/BrokenRecord.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions src/playback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 16 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

2 comments on commit 69f9909

@christopher-dG
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/24019

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 69f99097c10aa31305e0508f0f94daba17425c2d
git push origin v0.1.2

Please sign in to comment.