Skip to content

Commit 2787bfb

Browse files
authored
Merge pull request #75 from JuliaWeb/tan/misc
updates to support HTTP.jl v0.8.0, drop Julia v0.7, fix nightly build
2 parents a947ffb + 44cc880 commit 2787bfb

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ os:
33
- osx
44
- linux
55
julia:
6-
- 0.7
76
- 1.0
87
- nightly
98
matrix:

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.7
1+
julia 1.0
22
ZMQ 0.3.3
33
JSON
4-
HTTP 0.6.12
4+
HTTP 0.8.0

src/APIResponder.jl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ APIResponder(addr::String, ctx::Context=Context(), bound::Bool=true, id=nothing,
3030
APIResponder(ip::IPv4, port::Int, ctx::Context=Context()) = APIResponder("tcp://$ip:$port", ctx)
3131

3232
function Base.show(io::IO, x::APIResponder)
33-
println(io, "JuliaWebAPI.APIResponder with endpoints:")
34-
Base.show_comma_array(io, keys(x.endpoints), "","")
33+
print(io, "JuliaWebAPI.APIResponder with $(length(x.endpoints)) endpoints (", join(keys(x.endpoints), ","), ")")
3534
end
3635

3736
function default_endpoint(f::Function)
@@ -50,7 +49,7 @@ TODO: validate method belongs to module?
5049
function register(conn::APIResponder, f::Function;
5150
resp_json::Bool=false,
5251
resp_headers::Dict=Dict{String,String}(), endpt=default_endpoint(f))
53-
@debug("registering", endpt)
52+
@info("registering", endpt)
5453
conn.endpoints[endpt] = APISpec(f, resp_json, resp_headers)
5554
return conn # make fluent api possible
5655
end
@@ -147,11 +146,7 @@ function process(conn::APIResponder; async::Bool=false)
147146
respond(conn, nothing, :terminate, "")
148147
break
149148
else
150-
@static if isdefined(Base, Symbol("@error"))
151-
@error("invalid control command ", command)
152-
else
153-
err("invalid control command ", command)
154-
end
149+
@error("invalid control command ", command)
155150
continue
156151
end
157152
end
@@ -200,9 +195,5 @@ function logerr(msg, ex)
200195
iob = IOBuffer()
201196
write(iob, msg)
202197
showerror(iob, ex)
203-
@static if isdefined(Base, Symbol("@error"))
204-
@error(String(take!(iob)))
205-
else
206-
err(String(take!(iob)))
207-
end
198+
@error(String(take!(iob)))
208199
end

src/http_rpc_server.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HT
199199
catch e
200200
res = HTTP.Response(500)
201201
Base.showerror(stderr, e, catch_backtrace())
202-
err("Exception in handler: ", e)
202+
@error("Exception in handler: ", e)
203203
end
204204
@debug("response", res)
205205
return res
@@ -210,7 +210,7 @@ default_preproc(req::HTTP.Request) = nothing
210210
# add a multipart form handler, provide default
211211
struct HttpRpcServer{T,F}
212212
api::Channel{APIInvoker{T,F}}
213-
handler::HTTP.HandlerFunction
213+
handler::HTTP.RequestHandlerFunction
214214
end
215215

216216
HttpRpcServer(api::APIInvoker{T,F}, preproc::Function=default_preproc) where {T,F} = HttpRpcServer([api], preproc)
@@ -220,13 +220,15 @@ function HttpRpcServer(apis::Vector{APIInvoker{T,F}}, preproc::Function=default_
220220
put!(api, member)
221221
end
222222

223-
HttpRpcServer{T,F}(api, HTTP.HandlerFunction(req->http_handler(api, preproc, req)))
223+
handler_fn = (req)->JuliaWebAPI.http_handler(api, preproc, req)
224+
handler = HTTP.RequestHandlerFunction(handler_fn)
225+
HttpRpcServer{T,F}(api, handler)
224226
end
225227

226228
run_http(api::Union{Vector{APIInvoker{T,F}},APIInvoker{T,F}}, port::Int, preproc::Function=default_preproc; kwargs...) where {T,F} = run_http(HttpRpcServer(api, preproc), port; kwargs...)
227229
function run_http(httprpc::HttpRpcServer{T,F}, port::Int; kwargs...) where {T,F}
228-
@debug("running HTTP RPC server...")
229-
HTTP.listen(ip"0.0.0.0", port; kwargs...) do req::HTTP.Request
230+
@info("running HTTP RPC server...")
231+
HTTP.listen(ip"0.0.0.0", port; kwargs...) do req
230232
HTTP.handle(httprpc.handler, req)
231233
end
232234
end

0 commit comments

Comments
 (0)