mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine typo in protocol.
This commit is contained in:
parent
35fe05d62c
commit
8bc77387ff
7 changed files with 1328 additions and 2117 deletions
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
// default http listen port.
|
||||
// Default http listen port.
|
||||
#define SRS_DEFAULT_HTTP_PORT 80
|
||||
|
||||
#if !defined(SRS_EXPORT_LIBRTMP)
|
||||
|
@ -35,7 +35,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
||||
// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
||||
#ifndef _WIN32
|
||||
#include <sys/uio.h>
|
||||
#endif
|
||||
|
@ -46,7 +46,7 @@ class ISrsHttpMessage;
|
|||
class SrsHttpMuxEntry;
|
||||
class ISrsHttpResponseWriter;
|
||||
|
||||
// http specification
|
||||
// From http specification
|
||||
// CR = <US-ASCII CR, carriage return (13)>
|
||||
#define SRS_HTTP_CR SRS_CONSTS_CR // 0x0D
|
||||
// LF = <US-ASCII LF, linefeed (10)>
|
||||
|
@ -65,10 +65,10 @@ class ISrsHttpResponseWriter;
|
|||
// @see ISrsHttpMessage._http_ts_send_buffer
|
||||
#define SRS_HTTP_TS_SEND_BUFFER_SIZE 4096
|
||||
|
||||
// for ead all of http body, read each time.
|
||||
// For ead all of http body, read each time.
|
||||
#define SRS_HTTP_READ_CACHE_BYTES 4096
|
||||
|
||||
// for http parser macros
|
||||
// For http parser macros
|
||||
#define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS
|
||||
#define SRS_CONSTS_HTTP_GET HTTP_GET
|
||||
#define SRS_CONSTS_HTTP_POST HTTP_POST
|
||||
|
@ -80,10 +80,10 @@ class ISrsHttpResponseWriter;
|
|||
extern srs_error_t srs_go_http_error(ISrsHttpResponseWriter* w, int code);
|
||||
extern srs_error_t srs_go_http_error(ISrsHttpResponseWriter* w, int code, std::string error);
|
||||
|
||||
// get the status text of code.
|
||||
// Get the status text of code.
|
||||
extern std::string srs_generate_http_status_text(int status);
|
||||
|
||||
// bodyAllowedForStatus reports whether a given response status code
|
||||
// It reports whether a given response status code
|
||||
// permits a body. See RFC2616, section 4.4.
|
||||
extern bool srs_go_http_body_allowd(int status);
|
||||
|
||||
|
@ -95,7 +95,7 @@ extern bool srs_go_http_body_allowd(int status);
|
|||
// returns "application/octet-stream".
|
||||
extern std::string srs_go_http_detect(char* data, int size);
|
||||
|
||||
// state of message
|
||||
// The state of HTTP message
|
||||
enum SrsHttpParseState {
|
||||
SrsHttpParseStateInit = 0,
|
||||
SrsHttpParseStateStart,
|
||||
|
@ -121,27 +121,17 @@ public:
|
|||
// with CanonicalHeaderKey.
|
||||
virtual std::string get(std::string key);
|
||||
public:
|
||||
/**
|
||||
* get the content length. -1 if not set.
|
||||
*/
|
||||
// Get the content length. -1 if not set.
|
||||
virtual int64_t content_length();
|
||||
/**
|
||||
* set the content length by header "Content-Length"
|
||||
*/
|
||||
// set the content length by header "Content-Length"
|
||||
virtual void set_content_length(int64_t size);
|
||||
public:
|
||||
/**
|
||||
* get the content type. empty string if not set.
|
||||
*/
|
||||
// Get the content type. empty string if not set.
|
||||
virtual std::string content_type();
|
||||
/**
|
||||
* set the content type by header "Content-Type"
|
||||
*/
|
||||
// set the content type by header "Content-Type"
|
||||
virtual void set_content_type(std::string ct);
|
||||
public:
|
||||
/**
|
||||
* write all headers to string stream.
|
||||
*/
|
||||
// write all headers to string stream.
|
||||
virtual void write(std::stringstream& ss);
|
||||
};
|
||||
|
||||
|
@ -176,9 +166,9 @@ public:
|
|||
ISrsHttpResponseWriter();
|
||||
virtual ~ISrsHttpResponseWriter();
|
||||
public:
|
||||
// when chunked mode,
|
||||
// When chunked mode,
|
||||
// final the request to complete the chunked encoding.
|
||||
// for no-chunked mode,
|
||||
// For no-chunked mode,
|
||||
// final to send request, for example, content-length is 0.
|
||||
virtual srs_error_t final_request() = 0;
|
||||
|
||||
|
@ -191,13 +181,11 @@ public:
|
|||
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)
|
||||
// before writing the data. If the Header does not contain a
|
||||
// Content-Type line, Write adds a Content-Type set to the result of passing
|
||||
// the initial 512 bytes of written data to DetectContentType.
|
||||
// The initial 512 bytes of written data to DetectContentType.
|
||||
// @param data, the data to send. NULL to flush header only.
|
||||
virtual srs_error_t write(char* data, int size) = 0;
|
||||
/**
|
||||
* for the HTTP FLV, to writev to improve performance.
|
||||
* @see https://github.com/ossrs/srs/issues/405
|
||||
*/
|
||||
// for the HTTP FLV, to writev to improve performance.
|
||||
// @see https://github.com/ossrs/srs/issues/405
|
||||
virtual srs_error_t writev(const iovec* iov, int iovcnt, ssize_t* pnwrite) = 0;
|
||||
|
||||
// WriteHeader sends an HTTP response header with status code.
|
||||
|
@ -209,32 +197,26 @@ public:
|
|||
virtual void write_header(int code) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* the reader interface for http response.
|
||||
*/
|
||||
// The reader interface for http response.
|
||||
class ISrsHttpResponseReader
|
||||
{
|
||||
public:
|
||||
ISrsHttpResponseReader();
|
||||
virtual ~ISrsHttpResponseReader();
|
||||
public:
|
||||
/**
|
||||
* whether response read EOF.
|
||||
*/
|
||||
// Whether response read EOF.
|
||||
virtual bool eof() = 0;
|
||||
/**
|
||||
* read from the response body.
|
||||
* @param data, the buffer to read data buffer to.
|
||||
* @param nb_data, the max size of data buffer.
|
||||
* @param nb_read, the actual read size of bytes. NULL to ignore.
|
||||
* @remark when eof(), return error.
|
||||
* @remark for some server, the content-length not specified and not chunked,
|
||||
* which is actually the infinite chunked encoding, which after http header
|
||||
* is http response data, it's ok for browser. that is,
|
||||
* when user call this read, please ensure there is data to read(by content-length
|
||||
* or by chunked), because the sdk never know whether there is no data or
|
||||
* infinite chunked.
|
||||
*/
|
||||
// Read from the response body.
|
||||
// @param data, the buffer to read data buffer to.
|
||||
// @param nb_data, the max size of data buffer.
|
||||
// @param nb_read, the actual read size of bytes. NULL to ignore.
|
||||
// @remark when eof(), return error.
|
||||
// @remark for some server, the content-length not specified and not chunked,
|
||||
// which is actually the infinite chunked encoding, which after http header
|
||||
// is http response data, it's ok for browser. that is,
|
||||
// when user call this read, please ensure there is data to read(by content-length
|
||||
// or by chunked), because the sdk never know whether there is no data or
|
||||
// infinite chunked.
|
||||
virtual srs_error_t read(char* data, int nb_data, int* nb_read) = 0;
|
||||
};
|
||||
|
||||
|
@ -245,7 +227,7 @@ public:
|
|||
// ServeHTTP should write reply headers and data to the ResponseWriter
|
||||
// and then return. Returning signals that the request is finished
|
||||
// and that the HTTP server can move on to the next request on
|
||||
// the connection.
|
||||
// The connection.
|
||||
class ISrsHttpHandler
|
||||
{
|
||||
public:
|
||||
|
@ -300,33 +282,25 @@ public:
|
|||
public:
|
||||
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
||||
private:
|
||||
/**
|
||||
* serve the file by specified path
|
||||
*/
|
||||
// Serve the file by specified path
|
||||
virtual srs_error_t serve_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
virtual srs_error_t serve_flv_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
virtual srs_error_t serve_mp4_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
protected:
|
||||
/**
|
||||
* when access flv file with x.flv?start=xxx
|
||||
*/
|
||||
// When access flv file with x.flv?start=xxx
|
||||
virtual srs_error_t serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int offset);
|
||||
/**
|
||||
* when access mp4 file with x.mp4?range=start-end
|
||||
* @param start the start offset in bytes.
|
||||
* @param end the end offset in bytes. -1 to end of file.
|
||||
* @remark response data in [start, end].
|
||||
*/
|
||||
// When access mp4 file with x.mp4?range=start-end
|
||||
// @param start the start offset in bytes.
|
||||
// @param end the end offset in bytes. -1 to end of file.
|
||||
// @remark response data in [start, end].
|
||||
virtual srs_error_t serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int start, int end);
|
||||
protected:
|
||||
/**
|
||||
* copy the fs to response writer in size bytes.
|
||||
*/
|
||||
// Copy the fs to response writer in size bytes.
|
||||
virtual srs_error_t copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, ISrsHttpMessage* r, int size);
|
||||
};
|
||||
|
||||
// the mux entry for server mux.
|
||||
// the matcher info, for example, the pattern and handler.
|
||||
// The mux entry for server mux.
|
||||
// The matcher info, for example, the pattern and handler.
|
||||
class SrsHttpMuxEntry
|
||||
{
|
||||
public:
|
||||
|
@ -339,26 +313,20 @@ public:
|
|||
virtual ~SrsHttpMuxEntry();
|
||||
};
|
||||
|
||||
/**
|
||||
* the hijacker for http pattern match.
|
||||
*/
|
||||
// The hijacker for http pattern match.
|
||||
class ISrsHttpMatchHijacker
|
||||
{
|
||||
public:
|
||||
ISrsHttpMatchHijacker();
|
||||
virtual ~ISrsHttpMatchHijacker();
|
||||
public:
|
||||
/**
|
||||
* when match the request failed, no handler to process request.
|
||||
* @param request the http request message to match the handler.
|
||||
* @param ph the already matched handler, hijack can rewrite it.
|
||||
*/
|
||||
// When match the request failed, no handler to process request.
|
||||
// @param request the http request message to match the handler.
|
||||
// @param ph the already matched handler, hijack can rewrite it.
|
||||
virtual srs_error_t hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* the server mux, all http server should implements it.
|
||||
*/
|
||||
// The server mux, all http server should implements it.
|
||||
class ISrsHttpServeMux
|
||||
{
|
||||
public:
|
||||
|
@ -383,7 +351,7 @@ public:
|
|||
// "/images/" subtree.
|
||||
//
|
||||
// Note that since a pattern ending in a slash names a rooted subtree,
|
||||
// the pattern "/" matches all paths not matched by other registered
|
||||
// The pattern "/" matches all paths not matched by other registered
|
||||
// patterns, not just the URL with Path == "/".
|
||||
//
|
||||
// Patterns may optionally begin with a host name, restricting matches to
|
||||
|
@ -398,29 +366,25 @@ public:
|
|||
class SrsHttpServeMux : public ISrsHttpServeMux
|
||||
{
|
||||
private:
|
||||
// the pattern handler, to handle the http request.
|
||||
// The pattern handler, to handle the http request.
|
||||
std::map<std::string, SrsHttpMuxEntry*> entries;
|
||||
// the vhost handler.
|
||||
// when find the handler to process the request,
|
||||
// The vhost handler.
|
||||
// When find the handler to process the request,
|
||||
// append the matched vhost when pattern not starts with /,
|
||||
// for example, for pattern /live/livestream.flv of vhost ossrs.net,
|
||||
// the path will rewrite to ossrs.net/live/livestream.flv
|
||||
// For example, for pattern /live/livestream.flv of vhost ossrs.net,
|
||||
// The path will rewrite to ossrs.net/live/livestream.flv
|
||||
std::map<std::string, ISrsHttpHandler*> vhosts;
|
||||
// all hijackers for http match.
|
||||
// for example, the hstrs(http stream trigger rtmp source)
|
||||
// For example, the hstrs(http stream trigger rtmp source)
|
||||
// can hijack and install handler when request incoming and no handler.
|
||||
std::vector<ISrsHttpMatchHijacker*> hijackers;
|
||||
public:
|
||||
SrsHttpServeMux();
|
||||
virtual ~SrsHttpServeMux();
|
||||
public:
|
||||
/**
|
||||
* initialize the http serve mux.
|
||||
*/
|
||||
// Initialize the http serve mux.
|
||||
virtual srs_error_t initialize();
|
||||
/**
|
||||
* hijack the http match.
|
||||
*/
|
||||
// hijack the http match.
|
||||
virtual void hijack(ISrsHttpMatchHijacker* h);
|
||||
virtual void unhijack(ISrsHttpMatchHijacker* h);
|
||||
public:
|
||||
|
@ -437,10 +401,8 @@ private:
|
|||
virtual bool path_match(std::string pattern, std::string path);
|
||||
};
|
||||
|
||||
/**
|
||||
* The filter http mux, directly serve the http CORS requests,
|
||||
* while proxy to the worker mux for services.
|
||||
*/
|
||||
// The filter http mux, directly serve the http CORS requests,
|
||||
// while proxy to the worker mux for services.
|
||||
class SrsHttpCorsMux : public ISrsHttpServeMux
|
||||
{
|
||||
private:
|
||||
|
@ -457,7 +419,7 @@ public:
|
|||
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
||||
};
|
||||
|
||||
// for http header.
|
||||
// For http header.
|
||||
typedef std::pair<std::string, std::string> SrsHttpHeaderField;
|
||||
|
||||
// A Request represents an HTTP request received by a server
|
||||
|
@ -473,34 +435,28 @@ typedef std::pair<std::string, std::string> SrsHttpHeaderField;
|
|||
// 3. no body or user not confirmed infinite chunked.
|
||||
// For example:
|
||||
// ISrsHttpMessage* r = ...;
|
||||
// while (!r->eof()) r->read(); // read in mode 1 or 3.
|
||||
// while (!r->eof()) r->read(); // Read in mode 1 or 3.
|
||||
// For some server, we can confirm the body is infinite chunked:
|
||||
// ISrsHttpMessage* r = ...;
|
||||
// r->enter_infinite_chunked();
|
||||
// while (!r->eof()) r->read(); // read in mode 2
|
||||
// while (!r->eof()) r->read(); // Read in mode 2
|
||||
// @rmark for mode 2, the infinite chunked, all left data is body.
|
||||
class ISrsHttpMessage
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* use a buffer to read and send ts file.
|
||||
*/
|
||||
// Use a buffer to read and send ts file.
|
||||
// TODO: FIXME: remove it.
|
||||
char* _http_ts_send_buffer;
|
||||
public:
|
||||
ISrsHttpMessage();
|
||||
virtual ~ISrsHttpMessage();
|
||||
public:
|
||||
/**
|
||||
* the http request level cache.
|
||||
*/
|
||||
// The http request level cache.
|
||||
virtual char* http_ts_send_buffer();
|
||||
public:
|
||||
virtual uint8_t method() = 0;
|
||||
virtual uint16_t status_code() = 0;
|
||||
/**
|
||||
* method helpers.
|
||||
*/
|
||||
// Method helpers.
|
||||
virtual std::string method_str() = 0;
|
||||
virtual bool is_http_get() = 0;
|
||||
virtual bool is_http_put() = 0;
|
||||
|
@ -508,94 +464,74 @@ public:
|
|||
virtual bool is_http_delete() = 0;
|
||||
virtual bool is_http_options() = 0;
|
||||
public:
|
||||
/**
|
||||
* whether should keep the connection alive.
|
||||
*/
|
||||
// Whether should keep the connection alive.
|
||||
virtual bool is_keep_alive() = 0;
|
||||
/**
|
||||
* the uri contains the host and path.
|
||||
*/
|
||||
// The uri contains the host and path.
|
||||
virtual std::string uri() = 0;
|
||||
/**
|
||||
* the url maybe the path.
|
||||
*/
|
||||
// The url maybe the path.
|
||||
virtual std::string url() = 0;
|
||||
virtual std::string host() = 0;
|
||||
virtual std::string path() = 0;
|
||||
virtual std::string query() = 0;
|
||||
virtual std::string ext() = 0;
|
||||
/**
|
||||
* get the RESTful id,
|
||||
* for example, pattern is /api/v1/streams, path is /api/v1/streams/100,
|
||||
* then the rest id is 100.
|
||||
* @param pattern the handler pattern which will serve the request.
|
||||
* @return the REST id; -1 if not matched.
|
||||
*/
|
||||
// Get the RESTful id,
|
||||
// for example, pattern is /api/v1/streams, path is /api/v1/streams/100,
|
||||
// then the rest id is 100.
|
||||
// @param pattern the handler pattern which will serve the request.
|
||||
// @return the REST id; -1 if not matched.
|
||||
virtual int parse_rest_id(std::string pattern) = 0;
|
||||
public:
|
||||
/**
|
||||
* the left all data is chunked body, the infinite chunked mode,
|
||||
* which is chunked encoding without chunked header.
|
||||
* @remark error when message is in chunked or content-length specified.
|
||||
*/
|
||||
// The left all data is chunked body, the infinite chunked mode,
|
||||
// which is chunked encoding without chunked header.
|
||||
// @remark error when message is in chunked or content-length specified.
|
||||
virtual srs_error_t enter_infinite_chunked() = 0;
|
||||
/**
|
||||
* read body to string.
|
||||
* @remark for small http body.
|
||||
*/
|
||||
// Read body to string.
|
||||
// @remark for small http body.
|
||||
virtual srs_error_t body_read_all(std::string& body) = 0;
|
||||
/**
|
||||
* get the body reader, to read one by one.
|
||||
* @remark when body is very large, or chunked, use this.
|
||||
*/
|
||||
// Get the body reader, to read one by one.
|
||||
// @remark when body is very large, or chunked, use this.
|
||||
virtual ISrsHttpResponseReader* body_reader() = 0;
|
||||
/**
|
||||
* the content length, -1 for chunked or not set.
|
||||
*/
|
||||
// The content length, -1 for chunked or not set.
|
||||
virtual int64_t content_length() = 0;
|
||||
public:
|
||||
/**
|
||||
* get the param in query string,
|
||||
* for instance, query is "start=100&end=200",
|
||||
* then query_get("start") is "100", and query_get("end") is "200"
|
||||
*/
|
||||
// Get the param in query string,
|
||||
// for instance, query is "start=100&end=200",
|
||||
// then query_get("start") is "100", and query_get("end") is "200"
|
||||
virtual std::string query_get(std::string key) = 0;
|
||||
/**
|
||||
* get the headers.
|
||||
*/
|
||||
// Get the headers.
|
||||
virtual int request_header_count() = 0;
|
||||
virtual std::string request_header_key_at(int index) = 0;
|
||||
virtual std::string request_header_value_at(int index) = 0;
|
||||
public:
|
||||
/**
|
||||
* whether the current request is JSONP,
|
||||
* which has a "callback=xxx" in QueryString.
|
||||
*/
|
||||
// Whether the current request is JSONP,
|
||||
// which has a "callback=xxx" in QueryString.
|
||||
virtual bool is_jsonp() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
// The http-parser is license under MIT at https://github.com/nodejs/http-parser/blob/master/LICENSE-MIT
|
||||
// Version: 2.1 from https://github.com/nodejs/http-parser/releases/tag/v2.1
|
||||
|
||||
//Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
//
|
||||
// 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.
|
||||
#ifndef http_parser_h
|
||||
#define http_parser_h
|
||||
#ifdef __cplusplus
|
||||
|
@ -621,9 +557,8 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
||||
* faster
|
||||
*/
|
||||
// Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
||||
// faster
|
||||
#ifndef HTTP_PARSER_STRICT
|
||||
# define HTTP_PARSER_STRICT 1
|
||||
#endif
|
||||
|
@ -636,19 +571,18 @@ extern "C" {
|
|||
typedef struct http_parser_settings http_parser_settings;
|
||||
|
||||
|
||||
/* Callbacks should return non-zero to indicate an error. The parser will
|
||||
* then halt execution.
|
||||
*
|
||||
* The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
||||
* returning '1' from on_headers_complete will tell the parser that it
|
||||
* should not expect a body. This is used when receiving a response to a
|
||||
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
||||
* chunked' headers that indicate the presence of a body.
|
||||
*
|
||||
* http_data_cb does not return data chunks. It will be call arbitrarally
|
||||
* many times for each string. E.G. you might get 10 callbacks for "on_url"
|
||||
* each providing just a few characters more data.
|
||||
*/
|
||||
// Callbacks should return non-zero to indicate an error. The parser will
|
||||
// then halt execution.
|
||||
//
|
||||
// The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
||||
// returning '1' from on_headers_complete will tell the parser that it
|
||||
// should not expect a body. This is used when receiving a response to a
|
||||
// HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
||||
// chunked' headers that indicate the presence of a body.
|
||||
//
|
||||
// http_data_cb does not return data chunks. It will be call arbitrarally
|
||||
// many times for each string. E.G. you might get 10 callbacks for "on_url"
|
||||
// each providing just a few characters more data.
|
||||
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
|
||||
typedef int (*http_cb) (http_parser*);
|
||||
|
||||
|
@ -709,10 +643,8 @@ extern "C" {
|
|||
};
|
||||
|
||||
|
||||
/* Map for errno-related constants
|
||||
*
|
||||
* The provided argument should be a macro that takes 2 arguments.
|
||||
*/
|
||||
// Map for errno-related constants
|
||||
// The provided argument should be a macro that takes 2 arguments.
|
||||
#define HTTP_ERRNO_MAP(XX) \
|
||||
/* No error */ \
|
||||
XX(OK, "success") \
|
||||
|
@ -785,11 +717,10 @@ extern "C" {
|
|||
unsigned char method; /* requests only */
|
||||
unsigned char http_errno : 7;
|
||||
|
||||
/* 1 = Upgrade header was present and the parser has exited because of that.
|
||||
* 0 = No upgrade header present.
|
||||
* Should be checked when http_parser_execute() returns in addition to
|
||||
* error checking.
|
||||
*/
|
||||
// 1 = Upgrade header was present and the parser has exited because of that.
|
||||
// 0 = No upgrade header present.
|
||||
// Should be checked when http_parser_execute() returns in addition to
|
||||
// error checking.
|
||||
unsigned char upgrade : 1;
|
||||
|
||||
/** PUBLIC **/
|
||||
|
@ -821,13 +752,11 @@ extern "C" {
|
|||
};
|
||||
|
||||
|
||||
/* Result structure for http_parser_parse_url().
|
||||
*
|
||||
* Callers should index into field_data[] with UF_* values iff field_set
|
||||
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
||||
* because we probably have padding left over), we convert any port to
|
||||
* a uint16_t.
|
||||
*/
|
||||
// Result structure for http_parser_parse_url().
|
||||
// Callers should index into field_data[] with UF_* values iff field_set
|
||||
// has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
||||
// because we probably have padding left over), we convert any port to
|
||||
// a uint16_t.
|
||||
struct http_parser_url {
|
||||
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
|
||||
uint16_t port; /* Converted UF_PORT string */
|
||||
|
@ -848,12 +777,11 @@ extern "C" {
|
|||
size_t len);
|
||||
|
||||
|
||||
/* If http_should_keep_alive() in the on_headers_complete or
|
||||
* on_message_complete callback returns 0, then this should be
|
||||
* the last message on the connection.
|
||||
* If you are the server, respond with the "Connection: close" header.
|
||||
* If you are the client, close the connection.
|
||||
*/
|
||||
// If http_should_keep_alive() in the on_headers_complete or
|
||||
// on_message_complete callback returns 0, then this should be
|
||||
// The last message on the connection.
|
||||
// If you are the server, respond with the "Connection: close" header.
|
||||
// If you are the client, close the connection.
|
||||
int http_should_keep_alive(const http_parser *parser);
|
||||
|
||||
/* Returns a string version of the HTTP method. */
|
||||
|
@ -881,9 +809,7 @@ extern "C" {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* used to resolve the http uri.
|
||||
*/
|
||||
// Used to resolve the http uri.
|
||||
class SrsHttpUri
|
||||
{
|
||||
private:
|
||||
|
@ -897,9 +823,7 @@ public:
|
|||
SrsHttpUri();
|
||||
virtual ~SrsHttpUri();
|
||||
public:
|
||||
/**
|
||||
* initialize the http uri.
|
||||
*/
|
||||
// Initialize the http uri.
|
||||
virtual srs_error_t initialize(std::string _url);
|
||||
public:
|
||||
virtual std::string get_url();
|
||||
|
@ -909,10 +833,8 @@ public:
|
|||
virtual std::string get_path();
|
||||
virtual std::string get_query();
|
||||
private:
|
||||
/**
|
||||
* get the parsed url field.
|
||||
* @return return empty string if not set.
|
||||
*/
|
||||
// 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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue