@@ -154,21 +154,17 @@ function get_multipart_form_boundary(req::HTTP.Request)
154
154
end
155
155
156
156
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 ))
162
158
res = HTTP. Response (500 )
163
159
164
160
try
165
- comps = Compat . split (getfield (req, :target ), ' ?' , limit= 2 , keepempty= false )
161
+ comps = split (getfield (req, :target ), ' ?' , limit= 2 , keepempty= false )
166
162
if isempty (comps)
167
163
res = HTTP. Response (404 )
168
164
else
169
165
res = preproc (req)
170
166
if res === nothing
171
- comps = Compat . split (getfield (req, :target ), ' ?' , limit= 2 , keepempty= false )
167
+ comps = split (getfield (req, :target ), ' ?' , limit= 2 , keepempty= false )
172
168
path = popfirst! (comps)
173
169
data_dict = isempty (comps) ? Dict {String,String} () : HTTP. queryparams (comps[1 ])
174
170
multipart_boundary = get_multipart_form_boundary (req)
@@ -177,33 +173,21 @@ function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HT
177
173
else
178
174
data_dict = parsepostdata (req, data_dict, multipart_boundary)
179
175
end
180
- args = map (String, Compat . split (path, ' /' , keepempty= false ))
176
+ args = map (String, split (path, ' /' , keepempty= false ))
181
177
182
178
if isempty (args) || ! isvalidcmd (args[1 ])
183
179
res = HTTP. Response (404 )
184
180
else
185
181
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" )
191
183
api = take! (apis)
192
184
try
193
185
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)
199
187
res = httpresponse (api. format, apicall (api, cmd, args... ))
200
188
else
201
189
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)
207
191
res = httpresponse (api. format, apicall (api, cmd, args... ; vargs... ))
208
192
end
209
193
finally
@@ -214,14 +198,10 @@ function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HT
214
198
end
215
199
catch e
216
200
res = HTTP. Response (500 )
217
- Base. showerror (Compat . stderr , e, catch_backtrace ())
201
+ Base. showerror (stderr , e, catch_backtrace ())
218
202
err (" Exception in handler: " , e)
219
203
end
220
- @static if isdefined (Base, Symbol (" @debug" ))
221
- @debug (" response" , res)
222
- else
223
- Logging. debug (" \t response " , res)
224
- end
204
+ @debug (" response" , res)
225
205
return res
226
206
end
227
207
245
225
246
226
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... )
247
227
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..." )
253
229
HTTP. listen (ip " 0.0.0.0" , port; kwargs... ) do req:: HTTP.Request
254
230
HTTP. handle (httprpc. handler, req)
255
231
end
0 commit comments