mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
copy http-parser-2.1 into srs http stack.
This commit is contained in:
parent
fba1122835
commit
b2ae1acaa4
7 changed files with 2638 additions and 178 deletions
|
|
@ -1063,100 +1063,6 @@ int SrsHttpParser::on_body(http_parser* parser, const char* at, size_t length)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SrsHttpUri::SrsHttpUri()
|
||||
{
|
||||
port = SRS_DEFAULT_HTTP_PORT;
|
||||
}
|
||||
|
||||
SrsHttpUri::~SrsHttpUri()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsHttpUri::initialize(string _url)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
url = _url;
|
||||
const char* purl = url.c_str();
|
||||
|
||||
http_parser_url hp_u;
|
||||
if((ret = http_parser_parse_url(purl, url.length(), 0, &hp_u)) != 0){
|
||||
int code = ret;
|
||||
ret = ERROR_HTTP_PARSE_URI;
|
||||
|
||||
srs_error("parse url %s failed, code=%d, ret=%d", purl, code, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string field = get_uri_field(url, &hp_u, UF_SCHEMA);
|
||||
if(!field.empty()){
|
||||
schema = field;
|
||||
}
|
||||
|
||||
host = get_uri_field(url, &hp_u, UF_HOST);
|
||||
|
||||
field = get_uri_field(url, &hp_u, UF_PORT);
|
||||
if(!field.empty()){
|
||||
port = atoi(field.c_str());
|
||||
}
|
||||
|
||||
path = get_uri_field(url, &hp_u, UF_PATH);
|
||||
srs_info("parse url %s success", purl);
|
||||
|
||||
query = get_uri_field(url, &hp_u, UF_QUERY);
|
||||
srs_info("parse query %s success", query.c_str());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_url()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_schema()
|
||||
{
|
||||
return schema;
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_host()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
int SrsHttpUri::get_port()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_path()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_query()
|
||||
{
|
||||
return query;
|
||||
}
|
||||
|
||||
string SrsHttpUri::get_uri_field(string uri, http_parser_url* hp_u, http_parser_url_fields field)
|
||||
{
|
||||
if((hp_u->field_set & (1 << field)) == 0){
|
||||
return "";
|
||||
}
|
||||
|
||||
srs_verbose("uri field matched, off=%d, len=%d, value=%.*s",
|
||||
hp_u->field_data[field].off,
|
||||
hp_u->field_data[field].len,
|
||||
hp_u->field_data[field].len,
|
||||
uri.c_str() + hp_u->field_data[field].off);
|
||||
|
||||
int offset = hp_u->field_data[field].off;
|
||||
int len = hp_u->field_data[field].len;
|
||||
|
||||
return uri.substr(offset, len);
|
||||
}
|
||||
|
||||
SrsHttpConn::SrsHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m)
|
||||
: SrsConnection(cm, fd)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#ifdef SRS_AUTO_HTTP_CORE
|
||||
#include <http_parser.h>
|
||||
#endif
|
||||
|
||||
#ifdef SRS_AUTO_HTTP_CORE
|
||||
|
||||
#include <map>
|
||||
|
|
@ -348,41 +344,6 @@ private:
|
|||
static int on_body(http_parser* parser, const char* at, size_t length);
|
||||
};
|
||||
|
||||
/**
|
||||
* used to resolve the http uri.
|
||||
*/
|
||||
class SrsHttpUri
|
||||
{
|
||||
private:
|
||||
std::string url;
|
||||
std::string schema;
|
||||
std::string host;
|
||||
int port;
|
||||
std::string path;
|
||||
std::string query;
|
||||
public:
|
||||
SrsHttpUri();
|
||||
virtual ~SrsHttpUri();
|
||||
public:
|
||||
/**
|
||||
* initialize the http uri.
|
||||
*/
|
||||
virtual int initialize(std::string _url);
|
||||
public:
|
||||
virtual std::string get_url();
|
||||
virtual std::string get_schema();
|
||||
virtual std::string get_host();
|
||||
virtual int get_port();
|
||||
virtual std::string get_path();
|
||||
virtual std::string get_query();
|
||||
private:
|
||||
/**
|
||||
* get the parsed url field.
|
||||
* @return return empty string if not set.
|
||||
*/
|
||||
virtual std::string get_uri_field(std::string uri, http_parser_url* hp_u, http_parser_url_fields field);
|
||||
};
|
||||
|
||||
class SrsHttpConn : public SrsConnection
|
||||
{
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#ifdef SRS_AUTO_HTTP_CALLBACK
|
||||
|
||||
#include <http_parser.h>
|
||||
|
||||
class SrsHttpUri;
|
||||
class SrsStSocket;
|
||||
class SrsRequest;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue