mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #1657, Support HTTPS API
This commit is contained in:
parent
7916214e27
commit
272ca9d0f6
20 changed files with 647 additions and 11 deletions
|
@ -916,6 +916,17 @@ srs_error_t SrsHttpUri::initialize(string _url)
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsHttpUri::set_schema(std::string v)
|
||||
{
|
||||
schema = v;
|
||||
|
||||
// Update url with new schema.
|
||||
size_t pos = url.find("://");
|
||||
if (pos != string::npos) {
|
||||
url = schema + "://" + url.substr(pos + 3);
|
||||
}
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_url()
|
||||
{
|
||||
return url;
|
||||
|
|
|
@ -525,6 +525,8 @@ public:
|
|||
public:
|
||||
// Initialize the http uri.
|
||||
virtual srs_error_t initialize(std::string _url);
|
||||
// After parsed the message, set the schema to https.
|
||||
virtual void set_schema(std::string v);
|
||||
public:
|
||||
virtual std::string get_url();
|
||||
virtual std::string get_schema();
|
||||
|
|
|
@ -59,16 +59,16 @@ SrsSslClient::SrsSslClient(SrsTcpClient* tcp)
|
|||
|
||||
SrsSslClient::~SrsSslClient()
|
||||
{
|
||||
if (ssl_ctx) {
|
||||
SSL_CTX_free(ssl_ctx);
|
||||
ssl_ctx = NULL;
|
||||
}
|
||||
|
||||
if (ssl) {
|
||||
// this function will free bio_in and bio_out
|
||||
SSL_free(ssl);
|
||||
ssl = NULL;
|
||||
}
|
||||
|
||||
if (ssl_ctx) {
|
||||
SSL_CTX_free(ssl_ctx);
|
||||
ssl_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
srs_error_t SrsSslClient::handshake()
|
||||
|
@ -77,9 +77,9 @@ srs_error_t SrsSslClient::handshake()
|
|||
|
||||
// For HTTPS, try to connect over security transport.
|
||||
#if (OPENSSL_VERSION_NUMBER < 0x10002000L) // v1.0.2
|
||||
SSL_CTX* ssl_ctx = SSL_CTX_new(TLS_method());
|
||||
ssl_ctx = SSL_CTX_new(TLS_method());
|
||||
#else
|
||||
SSL_CTX* ssl_ctx = SSL_CTX_new(TLSv1_2_method());
|
||||
ssl_ctx = SSL_CTX_new(TLSv1_2_method());
|
||||
#endif
|
||||
SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, srs_verify_callback);
|
||||
srs_assert(SSL_CTX_set_cipher_list(ssl_ctx, "ALL") == 1);
|
||||
|
|
|
@ -414,6 +414,11 @@ srs_error_t SrsHttpMessage::set_url(string url, bool allow_jsonp)
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsHttpMessage::set_https(bool v)
|
||||
{
|
||||
_uri->set_schema(v? "https" : "http");
|
||||
}
|
||||
|
||||
ISrsConnection* SrsHttpMessage::connection()
|
||||
{
|
||||
return owner_conn;
|
||||
|
|
|
@ -145,6 +145,8 @@ public:
|
|||
virtual void set_header(SrsHttpHeader* header, bool keep_alive);
|
||||
// set the original messages, then update the message.
|
||||
virtual srs_error_t set_url(std::string url, bool allow_jsonp);
|
||||
// After parsed the message, set the schema to https.
|
||||
virtual void set_https(bool v);
|
||||
public:
|
||||
// Get the owner connection, maybe NULL.
|
||||
virtual ISrsConnection* connection();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue