Skip to content

Commit

Permalink
0.7 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Dec 22, 2017
1 parent 8768b45 commit 7bba13b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/HTTP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ if !isdefined(Base, :pairs)
pairs(x) = x
end

if !isdefined(Base, :Nothing)
const Nothing = Void
const Cvoid = Void
end

if VERSION < v"0.7.0-DEV.2575"
const Dates = Base.Dates
else
Expand Down
7 changes: 6 additions & 1 deletion src/handlers.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module Handlers

if !isdefined(Base, :Nothing)
const Nothing = Void
const Cvoid = Void
end

function val(v)
@static if VERSION < v"0.7.0-DEV.1395"
Val{v}()
Expand Down Expand Up @@ -59,7 +64,7 @@ struct Router <: Handler
segments::Dict{String, Val}
sym::Symbol
func::Function
function Router(ff::Union{Handler, Function, Void}=nothing)
function Router(ff::Union{Handler, Function, Nothing}=nothing)
sym = gensym()
if ff == nothing
f = @eval $sym(args...) = FourOhFour
Expand Down
4 changes: 2 additions & 2 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ function parse!(r, parser, bytes, len, lenient, host, method, maxuri, maxheader,
limit = min(limit, maxheader)
ptr = pointer(bytes, p)
@debug(PARSING_DEBUG, Base.escape_string(string('\'', Char(bytes[p]), '\'')))
p_cr = ccall(:memchr, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), ptr, CR, limit)
p_lf = ccall(:memchr, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), ptr, LF, limit)
p_cr = ccall(:memchr, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), ptr, CR, limit)
p_lf = ccall(:memchr, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), ptr, LF, limit)
@debug(PARSING_DEBUG, limit)
@debug(PARSING_DEBUG, Int(p_cr))
@debug(PARSING_DEBUG, Int(p_lf))
Expand Down
2 changes: 1 addition & 1 deletion src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function _precompile_()
@assert precompile(HTTP.ignorewhitespace, (Array{UInt8, 1}, Int64, Int64,))
@assert precompile(HTTP.Cookies.String, (HTTP.Cookies.Cookie, Bool,))
@assert precompile(HTTP.Cookies.shouldsend, (HTTP.Cookies.Cookie, Bool, String, String,))
@assert precompile(HTTP.Client, (Void, HTTP.RequestOptions,))
@assert precompile(HTTP.Client, (Nothing, HTTP.RequestOptions,))
@assert precompile(HTTP.Cookies.parsecookievalue, (Base.SubString{String}, Bool,))
@assert precompile(HTTP.ignorewhitespace, (Array{UInt8, 1}, UInt64, Int64,))
@assert precompile(HTTP.Cookies.hash, (HTTP.Cookies.Cookie, UInt,))
Expand Down
9 changes: 7 additions & 2 deletions src/server.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module Nitrogen

if !isdefined(Base, :Nothing)
const Nothing = Void
const Cvoid = Void
end

if VERSION < v"0.7.0-DEV.2575"
const Dates = Base.Dates
else
Expand Down Expand Up @@ -47,7 +52,7 @@ mutable struct ServerOptions
maxheader::Int64
maxbody::Int64
support100continue::Bool
chunksize::Union{Void, Int}
chunksize::Union{Nothing, Int}
logbody::Bool
end

Expand All @@ -58,7 +63,7 @@ ServerOptions(; tlsconfig::HTTP.TLS.SSLConfig=HTTP.TLS.SSLConfig(true),
maxheader::Int64=HTTP.DEFAULT_MAX_HEADER,
maxbody::Int64=HTTP.DEFAULT_MAX_BODY,
support100continue::Bool=true,
chunksize::Union{Void, Int}=nothing,
chunksize::Union{Nothing, Int}=nothing,
logbody::Bool=true) =
ServerOptions(tlsconfig, readtimeout, ratelimit, maxbody, maxuri, maxheader, support100continue, chunksize, logbody)

Expand Down
8 changes: 4 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ schemetype(::Type{TLS.SSLContext}) = https

const Headers = Dict{String, String}

const Option{T} = Union{T, Void}
not(::Void) = true
const Option{T} = Union{T, Nothing}
not(::Nothing) = true
not(x) = false
function get(value::T, name::Symbol, default::R)::R where {T, R}
val = getfield(value, name)::Option{R}
Expand Down Expand Up @@ -220,7 +220,7 @@ mutable struct Response
cookies::Vector{Cookie}
headers::Headers
body::FIFOBuffer
request::Union{Void,Request}
request::Union{Nothing,Request}
history::Vector{Response}
end

Expand All @@ -247,7 +247,7 @@ Response(; status::Int=200,
cookies::Vector{Cookie}=Cookie[],
headers::Headers=Headers(),
body::FIFOBuffer=FIFOBuffer(""),
request::Union{Void,Request}=nothing,
request::Union{Nothing,Request}=nothing,
history::Vector{Response}=Response[]) =
Response(status, Int16(1), Int16(1), cookies, headers, body, request, history)

Expand Down

0 comments on commit 7bba13b

Please sign in to comment.