Permalink
Browse files

http: Add WebSocket handler

  • Loading branch information...
sconemad committed May 26, 2017
1 parent 7bf51d5 commit 9c83f2455e2f3e44ede6e5cc33288d640c262c70
Showing with 549 additions and 9 deletions.
  1. +8 −0 http/HTTPModule.cpp
  2. +7 −5 http/Host.cpp
  3. +4 −2 http/Makefile.am
  4. +1 −0 http/MessageStream.h
  5. +431 −0 http/WebSocket.cpp
  6. +96 −0 http/WebSocket.h
  7. +2 −2 server/ServerModule.h
@@ -23,6 +23,7 @@ Free Software Foundation, Inc.,
#include <http/ConnectionStream.h>
#include <http/GetFile.h>
#include <http/DirIndex.h>
#include <http/WebSocket.h>
#include <http/Host.h>
#include <http/Client.h>

@@ -46,6 +47,7 @@ HTTPModule::HTTPModule()
scx::Stream::register_stream("http",this);
Handler::register_handler("getfile",this);
Handler::register_handler("dirindex",this);
Handler::register_handler("websocket",this);
scx::StandardContext::register_type("HTTPClient",this);

m_hosts = new HostMapper::Ref(new HostMapper(*this));
@@ -59,6 +61,7 @@ HTTPModule::~HTTPModule()
scx::Stream::unregister_stream("http",this);
Handler::unregister_handler("getfile",this);
Handler::unregister_handler("dirindex",this);
Handler::unregister_handler("websocket",this);
scx::StandardContext::unregister_type("HTTPClient",this);
}

@@ -212,6 +215,11 @@ void HTTPModule::provide(const std::string& type,
} else if ("dirindex" == type) {
object = new DirIndexHandler(this);

} else if ("websocket" == type) {
const scx::ScriptString* a_chain =
scx::get_method_arg<scx::ScriptString>(args,0,"chain");
if (!a_chain) return;
object = new WebSocketHandler(this,a_chain->get_string());
}
}

@@ -237,13 +237,15 @@ HandlerMap* Host::lookup_path_map(const std::string& name,
std::string key="/"+name;
pathinfo = "";

for (PatternMap::const_iterator it = m_path_mods.begin();
it != m_path_mods.end();
++it) {
// DEBUG_LOG("lookup_path_map "<<key<<" matching "<<it->first);
// First check for an exact match
PatternMap::const_iterator it = m_path_mods.find(key);
if (it != m_path_mods.end()) return it->second;

for (it = m_path_mods.begin(); it != m_path_mods.end(); ++it) {
//DEBUG_LOG("lookup_path_map "<<key<<" matching "<<it->first);
if (key.find(it->first) == 0) {
pathinfo = key.substr(it->first.length());
// DEBUG_LOG(" found "<<it->second->get_type());
//DEBUG_LOG(" found "<<it->second->get_type());
return it->second;
}
}
@@ -23,7 +23,8 @@ Request.cpp \
Response.cpp \
ResponseStream.cpp \
Session.cpp \
Status.cpp
Status.cpp \
WebSocket.cpp

httpincludedir = $(includedir)/http

@@ -46,7 +47,8 @@ Request.h \
Response.h \
ResponseStream.h \
Session.h \
Status.h
Status.h \
WebSocket.h

http_la_LDFLAGS = -module -avoid-version

@@ -65,6 +65,7 @@ class HTTP_API MessageStream : public scx::Stream {
void set_transparent();

void add_stream(scx::Stream* stream);
scx::Descriptor* get_endpoint() { return &endpoint(); }

HTTPModule& get_module();

Oops, something went wrong.

0 comments on commit 9c83f24

Please sign in to comment.