Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions Http/src/Http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
module Http

using Httplib
using Webstacklib, Httplib
include("RequestParser.jl")
export HttpHandler,
Server,
Expand Down Expand Up @@ -92,18 +92,16 @@ end
# sockets` is populated. Concrete types of `WebsocketInterface` are required
# to define these methods.
#
abstract WebsocketInterface
# `is_websocket_handshake` should determine if `req` is a valid websocket
# upgrade request.
#
function is_websocket_handshake(handler::WebsocketInterface, req::Request)
throw("`$(typeof(handler))` does not implement `is_websocket_handshake`.")
end
# `handle` is called when `is_websocket_handshake` returns true, and takes
# full control of the connection.
#
function handle(handler::WebsocketInterface, req::Request, client::Client)
throw("`$(typeof(handler))` does not implement `handle`.")
@interface type WebsocketInterface
# `is_websocket_handshake` should determine if `req` is a valid websocket
# upgrade request.
#
is_websocket_handshake(handler::WebsocketInterface, req::Request)

# `handle` is called when `is_websocket_handshake` returns true, and takes
# full control of the connection.
#
handle(handler::WebsocketInterface, req::Request, client::Client)
end

# `Server` types encapsulate an `HttpHandler` and optional
Expand Down
20 changes: 20 additions & 0 deletions Webstacklib/src/Webstacklib.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Webstacklib
export @interface

macro interface(iexp::Expr)
iexp.head == :type || throw("@interface macro expects a type expression, got $(exp.head)")
name = iexp.args[2]
oexp = :(begin abstract $(esc(name)) end)
for exp in iexp.args[3].args
if exp.head == :call
strexp = string(exp)[3:end-1]
err = string("method ", strexp, " for interface ", name, " not implemented.")
fun = Expr(:function, esc(exp), quote
throw($err)
end)
push!( oexp.args, fun )
end
end
oexp
end
end