1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/app/srs_app_http_conn.hpp

131 lines
4.4 KiB
C++
Raw Normal View History

2017-03-25 09:21:39 +00:00
/**
* The MIT License (MIT)
*
2019-12-30 02:10:35 +00:00
* Copyright (c) 2013-2020 Winlin
2017-03-25 09:21:39 +00:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
2014-03-27 04:14:04 +00:00
#ifndef SRS_APP_HTTP_CONN_HPP
#define SRS_APP_HTTP_CONN_HPP
#include <srs_core.hpp>
2015-05-22 14:34:03 +00:00
#include <map>
#include <string>
#include <vector>
2014-04-01 07:42:27 +00:00
2017-03-26 05:40:39 +00:00
#include <srs_service_http_conn.hpp>
#include <srs_app_reload.hpp>
#include <srs_kernel_file.hpp>
#include <srs_app_thread.hpp>
2015-05-22 14:34:03 +00:00
#include <srs_app_conn.hpp>
#include <srs_app_source.hpp>
class SrsServer;
class SrsSource;
class SrsRequest;
class SrsConsumer;
class SrsStSocket;
class SrsHttpParser;
class ISrsHttpMessage;
2014-04-02 10:07:34 +00:00
class SrsHttpHandler;
class SrsMessageQueue;
class SrsSharedPtrMessage;
2015-05-22 14:34:03 +00:00
class SrsRequest;
2015-09-22 01:01:47 +00:00
class SrsFastStream;
2015-05-22 14:34:03 +00:00
class SrsHttpUri;
class SrsConnection;
class SrsHttpMessage;
class SrsHttpStreamServer;
class SrsHttpStaticServer;
2015-05-22 14:34:03 +00:00
2019-04-30 00:24:52 +00:00
// The http connection which request the static or stream content.
class SrsHttpConn : public SrsConnection
{
protected:
SrsHttpParser* parser;
ISrsHttpServeMux* http_mux;
SrsHttpCorsMux* cors;
public:
2020-07-04 09:19:08 +00:00
SrsHttpConn(IConnectionManager* cm, srs_netfd_t fd, ISrsHttpServeMux* m, std::string cip, int port);
virtual ~SrsHttpConn();
2019-04-30 00:30:13 +00:00
// Interface ISrsKbpsDelta
public:
2019-01-01 09:36:27 +00:00
virtual void remark(int64_t* in, int64_t* out);
protected:
2017-07-29 13:39:57 +00:00
virtual srs_error_t do_cycle();
protected:
2019-04-30 00:24:52 +00:00
// When got http message,
// for the static service or api, discard any body.
// for the stream caster, for instance, http flv streaming, may discard the flv header or not.
2017-07-29 13:39:57 +00:00
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg) = 0;
private:
2017-07-29 13:39:57 +00:00
virtual srs_error_t process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
2019-04-30 00:24:52 +00:00
// When the connection disconnect, call this method.
// e.g. log msg of connection and report to other system.
// @param request: request which is converted by the last http message.
2017-07-29 13:39:57 +00:00
virtual srs_error_t on_disconnect(SrsRequest* req);
2019-04-30 00:30:13 +00:00
// Interface ISrsReloadHandler
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t on_reload_http_stream_crossdomain();
};
2019-04-30 00:24:52 +00:00
// Drop body of request, only process the response.
2015-06-14 11:42:43 +00:00
class SrsResponseOnlyHttpConn : public SrsHttpConn
{
public:
2020-07-04 09:19:08 +00:00
SrsResponseOnlyHttpConn(IConnectionManager* cm, srs_netfd_t fd, ISrsHttpServeMux* m, std::string cip, int port);
2015-06-14 11:42:43 +00:00
virtual ~SrsResponseOnlyHttpConn();
public:
// Directly read a HTTP request message.
// It's exported for HTTP stream, such as HTTP FLV, only need to write to client when
// serving it, but we need to start a thread to read message to detect whether FD is closed.
// @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427
// @remark Should only used in HTTP-FLV streaming connection.
2017-07-29 13:39:57 +00:00
virtual srs_error_t pop_message(ISrsHttpMessage** preq);
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg);
public:
// Set connection to expired.
virtual void expire();
};
2019-04-30 00:24:52 +00:00
// The http server, use http stream or static server to serve requests.
class SrsHttpServer : public ISrsHttpServeMux
2014-04-04 10:55:21 +00:00
{
private:
SrsServer* server;
SrsHttpStaticServer* http_static;
SrsHttpStreamServer* http_stream;
2014-04-04 10:55:21 +00:00
public:
SrsHttpServer(SrsServer* svr);
virtual ~SrsHttpServer();
2014-04-04 10:55:21 +00:00
public:
2017-06-09 05:29:23 +00:00
virtual srs_error_t initialize();
2019-04-30 00:30:13 +00:00
// Interface ISrsHttpServeMux
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
public:
2018-01-01 11:39:57 +00:00
virtual srs_error_t http_mount(SrsSource* s, SrsRequest* r);
virtual void http_unmount(SrsSource* s, SrsRequest* r);
};
2014-03-27 04:14:04 +00:00
#endif
2014-04-01 07:42:27 +00:00