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>
|
2015-01-18 09:17:07 +00:00
|
|
|
#include <srs_app_reload.hpp>
|
2015-01-18 11:49:03 +00:00
|
|
|
#include <srs_kernel_file.hpp>
|
2015-01-19 04:24:18 +00:00
|
|
|
#include <srs_app_thread.hpp>
|
2015-05-22 14:34:03 +00:00
|
|
|
#include <srs_app_conn.hpp>
|
2015-06-10 07:38:13 +00:00
|
|
|
#include <srs_app_source.hpp>
|
2014-04-01 04:36:56 +00:00
|
|
|
|
2015-05-03 15:34:59 +00:00
|
|
|
class SrsServer;
|
2015-01-18 10:39:53 +00:00
|
|
|
class SrsSource;
|
|
|
|
class SrsRequest;
|
2015-01-19 04:24:18 +00:00
|
|
|
class SrsConsumer;
|
2014-07-26 12:08:37 +00:00
|
|
|
class SrsStSocket;
|
2014-04-02 04:03:49 +00:00
|
|
|
class SrsHttpParser;
|
2015-05-22 14:24:05 +00:00
|
|
|
class ISrsHttpMessage;
|
2014-04-02 10:07:34 +00:00
|
|
|
class SrsHttpHandler;
|
2015-01-19 04:56:05 +00:00
|
|
|
class SrsMessageQueue;
|
2015-01-18 11:49:03 +00:00
|
|
|
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;
|
2015-06-14 06:06:39 +00:00
|
|
|
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.
|
2015-06-14 06:06:39 +00:00
|
|
|
class SrsHttpConn : public SrsConnection
|
2015-01-19 04:24:18 +00:00
|
|
|
{
|
2017-04-30 04:03:31 +00:00
|
|
|
protected:
|
2015-06-14 06:06:39 +00:00
|
|
|
SrsHttpParser* parser;
|
|
|
|
ISrsHttpServeMux* http_mux;
|
2016-12-15 08:22:04 +00:00
|
|
|
SrsHttpCorsMux* cors;
|
2015-01-18 14:51:07 +00:00
|
|
|
public:
|
2020-07-04 09:19:08 +00:00
|
|
|
SrsHttpConn(IConnectionManager* cm, srs_netfd_t fd, ISrsHttpServeMux* m, std::string cip, int port);
|
2015-06-14 06:06:39 +00:00
|
|
|
virtual ~SrsHttpConn();
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsKbpsDelta
|
2015-01-19 04:24:18 +00:00
|
|
|
public:
|
2019-01-01 09:36:27 +00:00
|
|
|
virtual void remark(int64_t* in, int64_t* out);
|
2015-05-24 17:02:06 +00:00
|
|
|
protected:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t do_cycle();
|
2015-06-14 06:06:39 +00:00
|
|
|
protected:
|
2019-04-30 00:24:52 +00:00
|
|
|
// When got http message,
|
2015-06-14 06:06:39 +00:00
|
|
|
// 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;
|
2015-02-03 08:01:07 +00:00
|
|
|
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
|
2016-12-15 08:22:04 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t on_reload_http_stream_crossdomain();
|
2015-02-03 08:01:07 +00:00
|
|
|
};
|
|
|
|
|
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
|
2015-02-03 08:01:07 +00:00
|
|
|
{
|
|
|
|
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();
|
2017-04-30 04:03:31 +00:00
|
|
|
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);
|
2015-02-03 08:01:07 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg);
|
2020-03-21 14:41:25 +00:00
|
|
|
public:
|
|
|
|
// Set connection to expired.
|
|
|
|
virtual void expire();
|
2015-02-03 08:01:07 +00:00
|
|
|
};
|
|
|
|
|
2019-04-30 00:24:52 +00:00
|
|
|
// The http server, use http stream or static server to serve requests.
|
2015-06-14 06:06:39 +00:00
|
|
|
class SrsHttpServer : public ISrsHttpServeMux
|
2014-04-04 10:55:21 +00:00
|
|
|
{
|
2015-03-14 11:45:13 +00:00
|
|
|
private:
|
|
|
|
SrsServer* server;
|
2015-06-14 06:06:39 +00:00
|
|
|
SrsHttpStaticServer* http_static;
|
|
|
|
SrsHttpStreamServer* http_stream;
|
2014-04-04 10:55:21 +00:00
|
|
|
public:
|
2015-03-14 11:45:13 +00:00
|
|
|
SrsHttpServer(SrsServer* svr);
|
2015-01-17 15:00:40 +00:00
|
|
|
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
|
2015-06-14 06:06:39 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-01-18 10:39:53 +00:00
|
|
|
public:
|
2018-01-01 11:39:57 +00:00
|
|
|
virtual srs_error_t http_mount(SrsSource* s, SrsRequest* r);
|
2015-03-14 01:52:47 +00:00
|
|
|
virtual void http_unmount(SrsSource* s, SrsRequest* r);
|
2015-05-04 10:11:52 +00:00
|
|
|
};
|
|
|
|
|
2014-03-27 04:14:04 +00:00
|
|
|
#endif
|
2014-04-01 07:42:27 +00:00
|
|
|
|