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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue