Skip to content

Commit 9811686

Browse files
authored
Merge pull request #70 from JuliaWeb/tan/misc
drop 0.6 support
2 parents 550f4b1 + ceb8572 commit 9811686

18 files changed

+50
-174
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.6
76
- 0.7
87
- 1.0
98
- nightly

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Create a file `srvr.jl` with the following code
3030
```julia
3131
# Load required packages
3232
using JuliaWebAPI
33-
using Compat
3433

3534
# Define functions testfn1 and testfn2 that we shall expose
3635
function testfn1(arg1, arg2; narg1="1", narg2="2")
@@ -51,8 +50,6 @@ julia srvr.jl &
5150
Then, on a Julia REPL, run the following code
5251
```julia
5352
using JuliaWebAPI #Load package
54-
using Logging
55-
Logging.configure(level=INFO);
5653

5754
#Create the ZMQ client that talks to the ZMQ listener above
5855
const apiclnt = APIInvoker("tcp://127.0.0.1:9999");

REQUIRE

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
julia 0.6
1+
julia 0.7
22
ZMQ 0.3.3
33
JSON
4-
Logging 0.3.1
5-
Compat 0.70.0
64
HTTP 0.6.12

examples/filedownload/httpsrvr.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using JuliaWebAPI
2-
using Logging
3-
using Base.Test
4-
5-
Logging.configure(level=INFO)
2+
using Test
63

74
const apiclnt = APIInvoker("tcp://127.0.0.1:9999")
85

9-
Logging.info("Open http://localhost:12000/listfiles with a web browser to download files")
6+
@info("Open http://localhost:12000/listfiles with a web browser to download files")
107
run_http(apiclnt, 12000)

examples/filedownload/srvr.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using JuliaWebAPI
2-
using Compat
3-
using Compat.Base64
4-
using Logging
2+
using Base64
53
using GZip
64

75
const CONTENT_DISPOSITION_TEMPLATE = "attachment; filename="

src/APIResponder.jl

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ TODO: validate method belongs to module?
5050
function register(conn::APIResponder, f::Function;
5151
resp_json::Bool=false,
5252
resp_headers::Dict=Dict{String,String}(), endpt=default_endpoint(f))
53-
@static if isdefined(Base, Symbol("@debug"))
54-
@debug("registering", endpt)
55-
else
56-
Logging.debug("registering endpoint [$endpt]")
57-
end
53+
@debug("registering", endpt)
5854
conn.endpoints[endpt] = APISpec(f, resp_json, resp_headers)
5955
return conn # make fluent api possible
6056
end
@@ -135,27 +131,15 @@ end
135131
"""start processing as a server"""
136132
function process(conn::APIResponder; async::Bool=false)
137133
if async
138-
@static if isdefined(Base, Symbol("@debug"))
139-
@debug("processing async...")
140-
else
141-
Logging.debug("processing async...")
142-
end
134+
@debug("processing async...")
143135
@async process(conn)
144136
else
145-
@static if isdefined(Base, Symbol("@debug"))
146-
@debug("processing...")
147-
else
148-
Logging.debug("processing...")
149-
end
137+
@debug("processing...")
150138
while true
151139
msg = juliaformat(conn.format, recvreq(conn.transport))
152140

153141
command = cmd(conn.format, msg)
154-
@static if isdefined(Base, Symbol("@info"))
155-
@info("received", command)
156-
else
157-
Logging.info("received request: ", command)
158-
end
142+
@info("received", command)
159143

160144
if startswith(command, ':') # is a control command
161145
ctrlcmd = Symbol(command[2:end])
@@ -189,11 +173,7 @@ function process(conn::APIResponder; async::Bool=false)
189173
end
190174
end
191175
close(conn.transport)
192-
@static if isdefined(Base, Symbol("@info"))
193-
@info("stopped processing.")
194-
else
195-
Logging.info("stopped processing.")
196-
end
176+
@info("stopped processing.")
197177
end
198178
conn
199179
end

src/JuliaWebAPI.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
__precompile__()
2-
31
module JuliaWebAPI
42

53
using ZMQ
64
using JSON
7-
using Logging
85
using HTTP
9-
using Compat
10-
using Compat.Base64
11-
using Compat.Sockets
12-
using Compat.Serialization
6+
using Base64
7+
using Sockets
8+
using Serialization
139

1410
import Base: close
1511

src/http_rpc_server.jl

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,17 @@ function get_multipart_form_boundary(req::HTTP.Request)
154154
end
155155

156156
function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HTTP.Request) where {T,F}
157-
@static if isdefined(Base, Symbol("@info"))
158-
@info("processing", target=getfield(req, :target))
159-
else
160-
Logging.info("processing request ", req)
161-
end
157+
@info("processing", target=getfield(req, :target))
162158
res = HTTP.Response(500)
163159

164160
try
165-
comps = Compat.split(getfield(req, :target), '?', limit=2, keepempty=false)
161+
comps = split(getfield(req, :target), '?', limit=2, keepempty=false)
166162
if isempty(comps)
167163
res = HTTP.Response(404)
168164
else
169165
res = preproc(req)
170166
if res === nothing
171-
comps = Compat.split(getfield(req, :target), '?', limit=2, keepempty=false)
167+
comps = split(getfield(req, :target), '?', limit=2, keepempty=false)
172168
path = popfirst!(comps)
173169
data_dict = isempty(comps) ? Dict{String,String}() : HTTP.queryparams(comps[1])
174170
multipart_boundary = get_multipart_form_boundary(req)
@@ -177,33 +173,21 @@ function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HT
177173
else
178174
data_dict = parsepostdata(req, data_dict, multipart_boundary)
179175
end
180-
args = map(String, Compat.split(path, '/', keepempty=false))
176+
args = map(String, split(path, '/', keepempty=false))
181177

182178
if isempty(args) || !isvalidcmd(args[1])
183179
res = HTTP.Response(404)
184180
else
185181
cmd = popfirst!(args)
186-
@static if isdefined(Base, Symbol("@info"))
187-
@info("waiting for a handler")
188-
else
189-
Logging.info("waiting for a handler")
190-
end
182+
@info("waiting for a handler")
191183
api = take!(apis)
192184
try
193185
if isempty(data_dict)
194-
@static if isdefined(Base, Symbol("@debug"))
195-
@debug("calling", cmd, args)
196-
else
197-
Logging.debug("calling cmd ", cmd, ", with args ", args)
198-
end
186+
@debug("calling", cmd, args)
199187
res = httpresponse(api.format, apicall(api, cmd, args...))
200188
else
201189
vargs = make_vargs(data_dict)
202-
@static if isdefined(Base, Symbol("@debug"))
203-
@debug("calling", cmd, args, vargs)
204-
else
205-
Logging.debug("calling cmd ", cmd, ", with args ", args, ", vargs ", vargs)
206-
end
190+
@debug("calling", cmd, args, vargs)
207191
res = httpresponse(api.format, apicall(api, cmd, args...; vargs...))
208192
end
209193
finally
@@ -214,14 +198,10 @@ function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HT
214198
end
215199
catch e
216200
res = HTTP.Response(500)
217-
Base.showerror(Compat.stderr, e, catch_backtrace())
201+
Base.showerror(stderr, e, catch_backtrace())
218202
err("Exception in handler: ", e)
219203
end
220-
@static if isdefined(Base, Symbol("@debug"))
221-
@debug("response", res)
222-
else
223-
Logging.debug("\tresponse ", res)
224-
end
204+
@debug("response", res)
225205
return res
226206
end
227207

@@ -245,11 +225,7 @@ end
245225

246226
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...)
247227
function run_http(httprpc::HttpRpcServer{T,F}, port::Int; kwargs...) where {T,F}
248-
@static if isdefined(Base, Symbol("@debug"))
249-
@debug("running HTTP RPC server...")
250-
else
251-
Logging.debug("running HTTP RPC server...")
252-
end
228+
@debug("running HTTP RPC server...")
253229
HTTP.listen(ip"0.0.0.0", port; kwargs...) do req::HTTP.Request
254230
HTTP.handle(httprpc.handler, req)
255231
end

src/msgformat.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ function _dict_fmt(code::Int, headers::Dict{String,String}, resp, id=nothing)
9191

9292
if !isempty(headers)
9393
msg["hdrs"] = headers
94-
@static if isdefined(Base, Symbol("@debug"))
95-
@debug("sending headers", headers)
96-
else
97-
Logging.debug("sending headers: ", headers)
98-
end
94+
@debug("sending headers", headers)
9995
end
10096

10197
msg["code"] = code

src/transport.jl

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,21 @@ struct ZMQTransport <: AbstractTransport
2121
end
2222

2323
function sendrecv(conn::ZMQTransport, msgstr)
24-
@static if isdefined(Base, Symbol("@debug"))
25-
@debug("sending request", msgstr)
26-
else
27-
Logging.debug("sending request: ", msgstr)
28-
end
24+
@debug("sending request", msgstr)
2925
ZMQ.send(conn.sock, ZMQ.Message(msgstr))
3026
respstr = unsafe_string(ZMQ.recv(conn.sock))
31-
@static if isdefined(Base, Symbol("@debug"))
32-
@debug("received response", respstr)
33-
else
34-
Logging.debug("received response: ", respstr)
35-
end
27+
@debug("received response", respstr)
3628
respstr
3729
end
3830

3931
function sendresp(conn::ZMQTransport, msgstr)
40-
@static if isdefined(Base, Symbol("@debug"))
41-
@debug("sending response", msgstr)
42-
else
43-
Logging.debug("sending response: ", msgstr)
44-
end
32+
@debug("sending response", msgstr)
4533
ZMQ.send(conn.sock, ZMQ.Message(msgstr))
4634
end
4735

4836
function recvreq(conn::ZMQTransport)
4937
reqstr = unsafe_string(ZMQ.recv(conn.sock))
50-
@static if isdefined(Base, Symbol("@debug"))
51-
@debug("received request", reqstr)
52-
else
53-
Logging.debug("received request: ", reqstr)
54-
end
38+
@debug("received request", reqstr)
5539
reqstr
5640
end
5741

@@ -78,40 +62,24 @@ const InProcChannels = Dict{Symbol,Tuple{Channel{Any},Channel{Any}}}()
7862
function sendrecv(conn::InProcTransport, msg)
7963
clntq,srvrq = InProcChannels[conn.name]
8064

81-
@static if isdefined(Base, Symbol("@debug"))
82-
@debug("sending request", msg)
83-
else
84-
Logging.debug("sending request: ", msg)
85-
end
65+
@debug("sending request", msg)
8666
put!(srvrq, msg)
8767
resp = take!(clntq)
88-
@static if isdefined(Base, Symbol("@debug"))
89-
@debug("received response", resp)
90-
else
91-
Logging.debug("received response: ", resp)
92-
end
68+
@debug("received response", resp)
9369
resp
9470
end
9571

9672
function sendresp(conn::InProcTransport, msg)
9773
clntq,srvrq = InProcChannels[conn.name]
98-
@static if isdefined(Base, Symbol("@debug"))
99-
@debug("sending response", msg)
100-
else
101-
Logging.debug("sending response: ", msg)
102-
end
74+
@debug("sending response", msg)
10375
put!(clntq, msg)
10476
nothing
10577
end
10678

10779
function recvreq(conn::InProcTransport)
10880
clntq,srvrq = InProcChannels[conn.name]
10981
req = take!(srvrq)
110-
@static if isdefined(Base, Symbol("@debug"))
111-
@debug("received request", req)
112-
else
113-
Logging.debug("received request: ", req)
114-
end
82+
@debug("received request", req)
11583
req
11684
end
11785

0 commit comments

Comments
 (0)