1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #324, refine code for hstrs, support hijack handler.

This commit is contained in:
winlin 2015-03-14 14:55:45 +08:00
parent 5c6ef6ded6
commit 995b130090
4 changed files with 172 additions and 9 deletions

View file

@ -288,6 +288,7 @@ protected:
};
// the mux entry for server mux.
// the matcher info, for example, the pattern and handler.
class SrsHttpMuxEntry
{
public:
@ -300,6 +301,23 @@ public:
virtual ~SrsHttpMuxEntry();
};
/**
* the hijacker for http pattern match.
*/
class ISrsHttpMatchHijacker
{
public:
ISrsHttpMatchHijacker();
virtual ~ISrsHttpMatchHijacker();
public:
/**
* when match the request failed, no handler to process request.
* @param request the http request message to match the handler.
* @param ph the already matched handler, hijack can rewrite it.
*/
virtual int hijack(SrsHttpMessage* request, ISrsHttpHandler** ph) = 0;
};
// ServeMux is an HTTP request multiplexer.
// It matches the URL of each incoming request against a list of registered
// patterns and calls the handler for the pattern that
@ -338,6 +356,10 @@ private:
// for example, for pattern /live/livestream.flv of vhost ossrs.net,
// the path will rewrite to ossrs.net/live/livestream.flv
std::map<std::string, ISrsHttpHandler*> vhosts;
// all hijackers for http match.
// for example, the hstrs(http stream trigger rtmp source)
// can hijack and install handler when request incoming and no handler.
std::vector<ISrsHttpMatchHijacker*> hijackers;
public:
SrsHttpServeMux();
virtual ~SrsHttpServeMux();
@ -346,6 +368,11 @@ public:
* initialize the http serve mux.
*/
virtual int initialize();
/**
* hijack the http match.
*/
virtual void hijack(ISrsHttpMatchHijacker* h);
virtual void unhijack(ISrsHttpMatchHijacker* h);
public:
// Handle registers the handler for the given pattern.
// If a handler already exists for pattern, Handle panics.
@ -442,6 +469,10 @@ private:
*/
std::string _url;
/**
* the extension of file, for example, .flv
*/
std::string _ext;
/**
* parsed http header.
*/
http_parser _header;
@ -505,6 +536,7 @@ public:
virtual std::string url();
virtual std::string host();
virtual std::string path();
virtual std::string ext();
public:
/**
* read body to string.