Skip to content

Commit 8768b45

Browse files
committed
0.6/0.7 compat
1 parent 53e32d4 commit 8768b45

File tree

12 files changed

+71
-37
lines changed

12 files changed

+71
-37
lines changed

src/HTTP.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ end
2020
using Unicode
2121
end
2222

23+
macro uninit(expr)
24+
if !isdefined(Base, :uninitialized)
25+
splice!(expr.args, 2)
26+
end
27+
return esc(expr)
28+
end
29+
30+
if !isdefined(Base, :pairs)
31+
pairs(x) = x
32+
end
33+
2334
if VERSION < v"0.7.0-DEV.2575"
2435
const Dates = Base.Dates
2536
else

src/client.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ function request(client::Client, req::Request, opts::RequestOptions, stream::Boo
332332
retry >= opts.retries::Int && throw(err)
333333
return request(client, req, opts, stream, history, retry + 1, verbose)
334334
end
335-
@log "received response"
335+
@log "received response: $response"
336336
opts.managecookies::Bool && !isempty(response.cookies) && (@log("caching received cookies for host: " * join(map(x->x.name, response.cookies), ", ")); union!(get!(client.cookies, host, Set{Cookie}()), response.cookies))
337337
response.history = history
338338
if opts.allowredirects::Bool && req.method != HEAD && (300 <= status(response) < 400)

src/cookies.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ if VERSION >= v"0.7.0-DEV.2915"
4040
using Unicode
4141
end
4242

43+
if !isdefined(Base, :pairs)
44+
pairs(x) = x
45+
end
46+
47+
4348
export Cookie
4449

4550
import Base.==
@@ -85,7 +90,7 @@ mutable struct Cookie
8590
end
8691

8792
function Cookie(cookie::Cookie; kwargs...)
88-
for (k, v) in kwargs
93+
for (k, v) in pairs(kwargs)
8994
setfield!(cookie, k, convert(fieldtype(Cookie, k), v))
9095
end
9196
return cookie
@@ -187,9 +192,13 @@ function readsetcookie(host, cookie)
187192
elseif lowerattr == "domain"
188193
c.domain = val
189194
elseif lowerattr == "max-age"
190-
secs = tryparse(Int, val)
191-
(isnull(secs) || val[1] == '0') && continue
192-
c.maxage = max(Base.get(secs), -1)
195+
try
196+
secs = parse(Int, val)
197+
val[1] == '0' && continue
198+
c.maxage = max(secs, -1)
199+
catch
200+
continue
201+
end
193202
elseif lowerattr == "expires"
194203
try
195204
c.expires = Dates.DateTime(val, Dates.RFC1123Format)

src/server.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ if VERSION < v"0.7.0-DEV.2575"
55
else
66
import Dates
77
end
8+
@static if !isdefined(Base, :Distributed)
9+
using Distributed
10+
end
811

912
using ..HTTP, ..Handlers
1013

src/sniff.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ const LITTLE_F = UInt8('f')
283283
const LITTLE_A = UInt8('a')
284284
const LITTLE_S = UInt8('s')
285285
const PERIOD = UInt8('.')
286-
const REF = Vector{Ptr{UInt8}}(uninitialized, 1)
286+
const REF = @uninit Vector{Ptr{UInt8}}(uninitialized, 1)
287287

288288
function isjson(bytes, i=0, maxlen=min(length(bytes), MAXSNIFFLENGTH))
289289
# ignore leading whitespace

src/types.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ mutable struct Response
220220
cookies::Vector{Cookie}
221221
headers::Headers
222222
body::FIFOBuffer
223-
request::Nullable{Request}
223+
request::Union{Void,Request}
224224
history::Vector{Response}
225225
end
226226

@@ -247,11 +247,11 @@ Response(; status::Int=200,
247247
cookies::Vector{Cookie}=Cookie[],
248248
headers::Headers=Headers(),
249249
body::FIFOBuffer=FIFOBuffer(""),
250-
request::Nullable{Request}=Nullable{Request}(),
250+
request::Union{Void,Request}=nothing,
251251
history::Vector{Response}=Response[]) =
252252
Response(status, Int16(1), Int16(1), cookies, headers, body, request, history)
253253

254-
Response(n::Integer, r::Request) = Response(; body=FIFOBuffer(n), request=Nullable(r))
254+
Response(n::Integer, r::Request) = Response(; body=FIFOBuffer(n), request=r)
255255
Response(s::Integer) = Response(; status=s)
256256
Response(s::Integer, msg) = Response(; status=s, body=FIFOBuffer(msg))
257257
Response(b::Union{Vector{UInt8}, String}) = Response(; headers=defaultheaders(Response), body=FIFOBuffer(b))
@@ -302,8 +302,8 @@ end
302302
function hasmessagebody(r::Response)
303303
if 100 <= status(r) < 200 || status(r) == 204 || status(r) == 304
304304
return false
305-
elseif !Base.isnull(request(r))
306-
req = Base.get(request(r))
305+
elseif request(r) !== nothing
306+
req = request(r)
307307
method(req) in (HEAD, CONNECT) && return false
308308
end
309309
return true

src/uri.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ escape(str::AbstractString, safe::Function=issafe) =
194194
escape(bytes::Vector{UInt8}) = bytes
195195
escape(v::Number) = escape(string(v))
196196
escape(v::Symbol) = escape(string(v))
197+
@static if VERSION < v"0.7.0-DEV.3017"
197198
escape(v::Nullable) = Base.isnull(v) ? "" : escape(get(v))
199+
end
198200

199201
escape(key, value) = string(escape(key), "=", escape(value))
200202
escape(key, values::Vector) = escape(key => v for v in values)

test/client.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ for sch in ("http", "https")
203203
req = HTTP.Request(HTTP.GET, uri, HTTP.Headers(), HTTP.FIFOBuffer())
204204
r = HTTP.request(req)
205205
@test HTTP.status(r) == 200
206-
@test !HTTP.isnull(HTTP.request(r))
206+
@test HTTP.request(r) !== nothing
207207
@test length(take!(r)) > 0
208208

209209
for c in HTTP.DEFAULT_CLIENT.httppool["httpbin.org"]

test/fifobuffer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
# ensure that `read(..., ::Type{UInt8})` returns a `UInt8`
184184
# https://github.com/JuliaWeb/HTTP.jl/issues/41
185185
f = HTTP.FIFOBuffer(5)
186-
b = Array{UInt8}(3)
186+
b = fill(0x00, 3)
187187
@test write(f, [0x01, 0x02, 0x03, 0x04]) == 4
188188
@test readbytes!(f, b) == 3
189189
@test b == [0x01, 0x02, 0x03]

test/parser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525

2626
function Message(; name::String="", kwargs...)
2727
m = Message(name)
28-
for (k, v) in kwargs
28+
for (k, v) in pairs(kwargs)
2929
try
3030
setfield!(m, k, v)
3131
catch e

0 commit comments

Comments
 (0)