Skip to content

Commit 549fe10

Browse files
bors[bot]quinnjmattBrzezinski
authored
Merge #560
560: Support HTTP.jl 1.0 r=iamed2 a=quinnj Co-authored-by: Jacob Quinn <[email protected]> Co-authored-by: mattBrzezinski <[email protected]>
2 parents deea490 + 1a56edc commit 549fe10

File tree

11 files changed

+33
-44
lines changed

11 files changed

+33
-44
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ jobs:
2828
include:
2929
# Add a job using the earliest version of Julia supported by this package
3030
- os: ubuntu-latest
31-
version: 1.3
32-
arch: x64
33-
# Add a 1.5 job because that's what Invenia actually uses
34-
- os: ubuntu-latest
35-
version: "1.5"
31+
version: 1.6
3632
arch: x64
3733
env:
3834
MINIO_ACCESS_KEY: minio

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ XMLDict = "228000da-037f-5747-90a9-8195ccbf91a5"
2424
[compat]
2525
Compat = "3.29"
2626
GitHub = "5"
27-
HTTP = "0.9.17"
27+
HTTP = "1"
2828
IniFile = "0.5"
2929
JSON = "0.18, 0.19, 0.20, 0.21"
3030
MbedTLS = "0.6, 0.7, 1"
@@ -33,7 +33,7 @@ OrderedCollections = "1.3"
3333
StableRNGs = "1"
3434
URIs = "1"
3535
XMLDict = "0.3, 0.4"
36-
julia = "1.3"
36+
julia = "1.6"
3737

3838
[extras]
3939
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

bors.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
status = [
2-
"Julia 1.3 - ubuntu-latest - x64",
3-
"Julia 1.5 - ubuntu-latest - x64",
2+
"Julia 1.6 - ubuntu-latest - x64",
43
"Julia 1 - macOS-latest - x64",
54
"Julia 1 - ubuntu-latest - x64",
65
]

src/AWSExceptions.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module AWSExceptions
22

33
using HTTP
4-
using HTTP.MessageRequest: body_was_streamed
54
using JSON
65
using XMLDict
76
using XMLDict: XMLDictElement
@@ -120,7 +119,7 @@ function AWSException(e::HTTP.StatusError, body::AbstractString)
120119
message = get(info, "Message", message)
121120
message = get(info, "message", message)
122121

123-
streamed_body = e.response.body == body_was_streamed ? body : nothing
122+
streamed_body = !HTTP.isbytes(e.response.body) ? body : nothing
124123

125124
return AWSException(code, message, info, e, streamed_body)
126125
end

src/deprecated.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ function legacy_response(
77

88
# When a user defined I/O stream is passed in use the actual `HTTP.Response` body
99
# instead of the `AWS.Response` body which requires the I/O stream to be seekable.
10-
body = request.response_stream !== nothing ? response.response.body : response.body
10+
body = if request.response_stream !== nothing
11+
b"[Message Body was streamed]"
12+
else
13+
response.body
14+
end
1115

1216
# The stored service name is always lowercase and may not match the module name
1317
# specified by the user. We'll assume that the typical casing used is titlecase.

src/utilities/credentials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function _ec2_metadata(metadata_endpoint::String)
158158

159159
return request === nothing ? nothing : String(request.body)
160160
catch e
161-
e isa HTTP.IOError || e isa HTTP.StatusError && e.status == 404 || rethrow(e)
161+
e isa HTTP.RequestError || e isa HTTP.StatusError && e.status == 404 || rethrow(e)
162162
end
163163

164164
return nothing

src/utilities/downloads_backend.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using HTTP.MessageRequest: body_was_streamed
2-
31
"""
42
DownloadsBackend <: AWS.AbstractBackend
53
@@ -125,9 +123,7 @@ function _http_request(backend::DownloadsBackend, request::Request, response_str
125123
end
126124

127125
function _http_response(req::Request, res::Downloads.Response; throw::Bool=true)
128-
response = HTTP.Response(
129-
res.status, res.headers; body=body_was_streamed, request=nothing
130-
)
126+
response = HTTP.Response(res.status, res.headers; body=IOBuffer(), request=nothing)
131127

132128
if throw && HTTP.iserror(response)
133129
target = HTTP.resource(HTTP.URI(req.url))

src/utilities/request.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ struct HTTPBackend <: AbstractBackend
2828
http_options::AbstractDict{Symbol,<:Any}
2929
end
3030

31+
function statuserror(status, resp)
32+
return HTTP.StatusError(status, resp.request.method, resp.request.target, resp)
33+
end
34+
3135
function HTTPBackend(; kwargs...)
3236
return if isempty(kwargs)
3337
HTTPBackend(LittleDict{Symbol,Any}())
@@ -129,7 +133,7 @@ function submit_request(aws::AbstractAWSConfig, request::Request; return_headers
129133
if HTTP.header(response, "Location") != ""
130134
request.url = HTTP.header(response, "Location")
131135
else
132-
e = HTTP.StatusError(response.status, response)
136+
e = statuserror(response.status, response)
133137
throw(AWSException(e, stream))
134138
end
135139
end
@@ -200,11 +204,6 @@ end
200204
function _http_request(http_backend::HTTPBackend, request::Request, response_stream::IO)
201205
http_options = merge(http_backend.http_options, request.http_options)
202206

203-
# HTTP options such as `status_exception` need to be used when creating the stack
204-
http_stack = HTTP.stack(;
205-
redirect=false, retry=false, aws_authorization=false, http_options...
206-
)
207-
208207
local buffer
209208
local response
210209

@@ -219,12 +218,12 @@ function _http_request(http_backend::HTTPBackend, request::Request, response_str
219218
buffer = Base.BufferStream()
220219

221220
response = @mock HTTP.request(
222-
http_stack,
223221
request.request_method,
224222
HTTP.URI(request.url),
225223
HTTP.mkheaders(request.headers),
226224
request.content;
227-
require_ssl_verification=false,
225+
redirect=false,
226+
retry=false,
228227
response_stream=buffer,
229228
http_options...,
230229
)
@@ -235,13 +234,8 @@ function _http_request(http_backend::HTTPBackend, request::Request, response_str
235234
end
236235

237236
check = function (s, e)
238-
# `Base.IOError` is needed because HTTP.jl can often have errors that aren't
239-
# caught and wrapped in an `HTTP.IOError`
240-
# https://github.com/JuliaWeb/HTTP.jl/issues/382
241-
return isa(e, Sockets.DNSError) ||
242-
isa(e, HTTP.ParseError) ||
243-
isa(e, HTTP.IOError) ||
244-
isa(e, Base.IOError) ||
237+
return isa(e, HTTP.ConnectError) ||
238+
isa(e, HTTP.RequestError) ||
245239
(isa(e, HTTP.StatusError) && _http_status(e) >= 500)
246240
end
247241

test/AWSExceptions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"status_code" => 400,
2525
)
2626

27-
expected["body"] = HTTP.MessageRequest.body_was_streamed
27+
expected["body"] = IOBuffer()
2828
expected["streamed_body"] = """
2929
<?xml version="1.0" encoding="UTF-8"?>
3030
<$err>
@@ -40,7 +40,7 @@
4040
resp = HTTP.Response(
4141
expected["status_code"], expected["headers"]; body=expected["body"], request=req
4242
)
43-
status_error = HTTP.StatusError(expected["status_code"], resp)
43+
status_error = AWS.statuserror(expected["status_code"], resp)
4444
ex = AWSException(status_error, expected["streamed_body"])
4545

4646
_test_exception(ex, expected, msg)
@@ -50,7 +50,7 @@
5050

5151
@testset "XMLRequest - Invalid XML" begin
5252
expected = Dict(
53-
"body" => HTTP.MessageRequest.body_was_streamed,
53+
"body" => IOBuffer(),
5454
"streamed_body" => """<?xml version="1.0" encoding="UTF-8"?>InvalidXML""",
5555
"headers" => ["Content-Type" => "application/xml"],
5656
"status_code" => 404,
@@ -59,7 +59,7 @@
5959
resp = HTTP.Response(
6060
expected["status_code"], expected["headers"]; body=expected["body"], request=req
6161
)
62-
status_error = HTTP.StatusError(expected["status_code"], resp)
62+
status_error = AWS.statuserror(expected["status_code"], resp)
6363
ex = @test_logs (:error,) AWSException(status_error, expected["streamed_body"])
6464

6565
@test ex.code == "404"
@@ -74,7 +74,7 @@
7474
"status_code" => 400,
7575
)
7676

77-
expected["body"] = HTTP.MessageRequest.body_was_streamed
77+
expected["body"] = IOBuffer()
7878
expected["streamed_body"] = """
7979
{
8080
"__type": "$(expected["code"])",
@@ -87,7 +87,7 @@
8787
resp = HTTP.Response(
8888
expected["status_code"], expected["headers"]; body=expected["body"], request=req
8989
)
90-
status_error = HTTP.StatusError(expected["status_code"], resp)
90+
status_error = AWS.statuserror(expected["status_code"], resp)
9191
ex = AWSException(status_error, expected["streamed_body"])
9292

9393
_test_exception(ex, expected, "$msg")

test/issues.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ try
171171
attempt_num += 1
172172
if attempt_num <= num_attempts_to_fail
173173
write(response_stream, data[1:(n - 1)]) # an incomplete stream that shouldn't be retained
174-
throw(HTTP.IOError(EOFError(), "msg"))
174+
throw(HTTP.RequestError(HTTP.Request(), EOFError()))
175175
else
176176
write(response_stream, data)
177177
return HTTP.Response(200, "{\"Location\": \"us-east-1\"}")
@@ -212,7 +212,7 @@ try
212212

213213
@testset "Fail all 4 attempts then throw" begin
214214
err_t = if AWS.DEFAULT_BACKEND[] isa AWS.HTTPBackend
215-
HTTP.IOError
215+
HTTP.RequestError
216216
else
217217
Downloads.RequestError
218218
end

0 commit comments

Comments
 (0)