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

extract http static and http stream from http conn.

This commit is contained in:
winlin 2015-06-14 14:06:39 +08:00
parent baa892a762
commit f8f6e438cc
15 changed files with 2160 additions and 1771 deletions

View file

@ -228,6 +228,11 @@ ISrsHttpHandler::~ISrsHttpHandler()
{
}
bool ISrsHttpHandler::is_not_found()
{
return false;
}
SrsHttpRedirectHandler::SrsHttpRedirectHandler(string u, int c)
{
url = u;
@ -253,6 +258,11 @@ SrsHttpNotFoundHandler::~SrsHttpNotFoundHandler()
{
}
bool SrsHttpNotFoundHandler::is_not_found()
{
return true;
}
int SrsHttpNotFoundHandler::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
return srs_go_http_error(w, SRS_CONSTS_HTTP_NotFound, SRS_CONSTS_HTTP_NotFound_str);
@ -487,6 +497,14 @@ ISrsHttpMatchHijacker::~ISrsHttpMatchHijacker()
{
}
ISrsHttpServeMux::ISrsHttpServeMux()
{
}
ISrsHttpServeMux::~ISrsHttpServeMux()
{
}
SrsHttpServeMux::SrsHttpServeMux()
{
}
@ -604,6 +622,19 @@ int SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handler)
return ret;
}
bool SrsHttpServeMux::can_serve(ISrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;
ISrsHttpHandler* h = NULL;
if ((ret = find_handler(r, &h)) != ERROR_SUCCESS) {
return false;
}
srs_assert(h);
return !h->is_not_found();
}
int SrsHttpServeMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;
@ -654,9 +685,9 @@ int SrsHttpServeMux::find_handler(ISrsHttpMessage* r, ISrsHttpHandler** ph)
}
}
static ISrsHttpHandler* h404 = new SrsHttpNotFoundHandler();
if (*ph == NULL) {
// TODO: FIXME: memory leak.
*ph = new SrsHttpNotFoundHandler();
*ph = h404;
}
return ret;

View file

@ -247,6 +247,7 @@ public:
ISrsHttpHandler();
virtual ~ISrsHttpHandler();
public:
virtual bool is_not_found();
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) = 0;
};
@ -270,6 +271,7 @@ public:
SrsHttpNotFoundHandler();
virtual ~SrsHttpNotFoundHandler();
public:
virtual bool is_not_found();
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
@ -347,6 +349,18 @@ public:
virtual int hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) = 0;
};
/**
* the server mux, all http server should implements it.
*/
class ISrsHttpServeMux
{
public:
ISrsHttpServeMux();
virtual ~ISrsHttpServeMux();
public:
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) = 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
@ -374,7 +388,7 @@ public:
// ServeMux also takes care of sanitizing the URL request path,
// redirecting any request containing . or .. elements to an
// equivalent .- and ..-free URL.
class SrsHttpServeMux
class SrsHttpServeMux : public ISrsHttpServeMux
{
private:
// the pattern handler, to handle the http request.
@ -406,7 +420,10 @@ public:
// Handle registers the handler for the given pattern.
// If a handler already exists for pattern, Handle panics.
virtual int handle(std::string pattern, ISrsHttpHandler* handler);
// interface ISrsHttpHandler
// whether the http muxer can serve the specified message,
// if not, user can try next muxer.
virtual bool can_serve(ISrsHttpMessage* r);
// interface ISrsHttpServeMux
public:
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
private: