Skip to content

Commit

Permalink
test_handler is back to original signature deals with request not stream
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei committed Nov 25, 2022
1 parent 491463b commit fc55503
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/HTTP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,12 @@ struct RequestHandlerFunction{F} <: RequestHandler
end

#handle(h::RequestHandlerFunction, req::Request, args...) = h.func(req, args...)
handle(h::RequestHandlerFunction, stream::HTTP.Streams.Stream, args...) = h.func(stream, args...)
function handle(h::RequestHandlerFunction, stream::HTTP.Streams.Stream, args...)
request = stream.message
request.response = h.func(request, args...)
request.response.request = request
write(stream, request.response.body)
end


"""
Expand Down Expand Up @@ -405,6 +410,7 @@ function serve(serverws::ServerWS, host, port, verbose)
handle(serverws.handler, stream)
end
catch err
@error "WebSocket: _servercoroutine CRASH\n$(sprint(showerror, err))"
put!(serverws.out, err)
put!(serverws.out, stacktrace(catch_backtrace()))
end
Expand Down
7 changes: 1 addition & 6 deletions test/client_server_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ end
`test_handler` is called by WebSockets inner function `_servercoroutine` for all accepted http requests
that are not upgrades. We don't check what's actually requested.
"""
function test_handler(stream::HTTP.Streams.Stream)
request = stream.message
request.response = HTTP.Response(200, "OK")
request.response.request = request
write(stream, request.response.body)
end
test_handler(req::HTTP.Request) = HTTP.Response(200, "OK")

"""
`test_wshandler` is called by WebSockets inner function
Expand Down

0 comments on commit fc55503

Please sign in to comment.