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

For #1657, support HTTPS client, for http-callback. 4.0.45

This commit is contained in:
winlin 2020-11-03 15:45:52 +08:00
parent 08e19406ef
commit d552a1a5fb
13 changed files with 343 additions and 31 deletions

View file

@ -29,6 +29,14 @@
#include <string>
#include <map>
#include <openssl/ssl.h>
#ifdef SRS_HTTPS
#if (OPENSSL_VERSION_NUMBER < 0x10002000L) // v1.0.2
#error "For https, we requires openssl 1.0.2+"
#endif
#endif
#include <srs_service_st.hpp>
#include <srs_http_stack.hpp>
@ -43,6 +51,26 @@ class SrsTcpClient;
// The default timeout for http client.
#define SRS_HTTP_CLIENT_TIMEOUT (30 * SRS_UTIME_SECONDS)
// The SSL client over TCP transport.
class SrsSslClient : virtual public ISrsReader, virtual public ISrsStreamWriter
{
private:
SrsTcpClient* transport;
private:
SSL_CTX* ssl_ctx;
SSL* ssl;
BIO* bio_in;
BIO* bio_out;
public:
SrsSslClient(SrsTcpClient* tcp);
virtual ~SrsSslClient();
public:
virtual srs_error_t handshake();
public:
virtual srs_error_t read(void* buf, size_t size, ssize_t* nread);
virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite);
};
// The client to GET/POST/PUT/DELETE over HTTP.
// @remark We will reuse the TCP transport until initialize or channel error,
// such as send/recv failed.
@ -64,17 +92,21 @@ private:
// The timeout in srs_utime_t.
srs_utime_t timeout;
srs_utime_t recv_timeout;
// The host name or ip.
// The schema, host name or ip.
std::string schema_;
std::string host;
int port;
private:
SrsSslClient* ssl_transport;
public:
SrsHttpClient();
virtual ~SrsHttpClient();
public:
// Initliaze the client, disconnect the transport, renew the HTTP parser.
// @param schema Should be http or https.
// @param tm The underlayer TCP transport timeout in srs_utime_t.
// @remark we will set default values in headers, which can be override by set_header.
virtual srs_error_t initialize(std::string h, int p, srs_utime_t tm = SRS_HTTP_CLIENT_TIMEOUT);
virtual srs_error_t initialize(std::string schema, std::string h, int p, srs_utime_t tm = SRS_HTTP_CLIENT_TIMEOUT);
// Set HTTP request header in header[k]=v.
// @return the HTTP client itself.
virtual SrsHttpClient* set_header(std::string k, std::string v);
@ -98,6 +130,8 @@ public:
private:
virtual void disconnect();
virtual srs_error_t connect();
ISrsStreamWriter* writer();
ISrsReader* reader();
};
#endif