http-parser replaced to llhttp.
This commit is contained in:
parent
a11c57226b
commit
b3dbf6e23f
37 changed files with 16281 additions and 3513 deletions
68
src/3rdparty/http-parser/AUTHORS
vendored
68
src/3rdparty/http-parser/AUTHORS
vendored
|
@ -1,68 +0,0 @@
|
||||||
# Authors ordered by first contribution.
|
|
||||||
Ryan Dahl <ry@tinyclouds.org>
|
|
||||||
Jeremy Hinegardner <jeremy@hinegardner.org>
|
|
||||||
Sergey Shepelev <temotor@gmail.com>
|
|
||||||
Joe Damato <ice799@gmail.com>
|
|
||||||
tomika <tomika_nospam@freemail.hu>
|
|
||||||
Phoenix Sol <phoenix@burninglabs.com>
|
|
||||||
Cliff Frey <cliff@meraki.com>
|
|
||||||
Ewen Cheslack-Postava <ewencp@cs.stanford.edu>
|
|
||||||
Santiago Gala <sgala@apache.org>
|
|
||||||
Tim Becker <tim.becker@syngenio.de>
|
|
||||||
Jeff Terrace <jterrace@gmail.com>
|
|
||||||
Ben Noordhuis <info@bnoordhuis.nl>
|
|
||||||
Nathan Rajlich <nathan@tootallnate.net>
|
|
||||||
Mark Nottingham <mnot@mnot.net>
|
|
||||||
Aman Gupta <aman@tmm1.net>
|
|
||||||
Tim Becker <tim.becker@kuriositaet.de>
|
|
||||||
Sean Cunningham <sean.cunningham@mandiant.com>
|
|
||||||
Peter Griess <pg@std.in>
|
|
||||||
Salman Haq <salman.haq@asti-usa.com>
|
|
||||||
Cliff Frey <clifffrey@gmail.com>
|
|
||||||
Jon Kolb <jon@b0g.us>
|
|
||||||
Fouad Mardini <f.mardini@gmail.com>
|
|
||||||
Paul Querna <pquerna@apache.org>
|
|
||||||
Felix Geisendörfer <felix@debuggable.com>
|
|
||||||
koichik <koichik@improvement.jp>
|
|
||||||
Andre Caron <andre.l.caron@gmail.com>
|
|
||||||
Ivo Raisr <ivosh@ivosh.net>
|
|
||||||
James McLaughlin <jamie@lacewing-project.org>
|
|
||||||
David Gwynne <loki@animata.net>
|
|
||||||
Thomas LE ROUX <thomas@november-eleven.fr>
|
|
||||||
Randy Rizun <rrizun@ortivawireless.com>
|
|
||||||
Andre Louis Caron <andre.louis.caron@usherbrooke.ca>
|
|
||||||
Simon Zimmermann <simonz05@gmail.com>
|
|
||||||
Erik Dubbelboer <erik@dubbelboer.com>
|
|
||||||
Martell Malone <martellmalone@gmail.com>
|
|
||||||
Bertrand Paquet <bpaquet@octo.com>
|
|
||||||
BogDan Vatra <bogdan@kde.org>
|
|
||||||
Peter Faiman <peter@thepicard.org>
|
|
||||||
Corey Richardson <corey@octayn.net>
|
|
||||||
Tóth Tamás <tomika_nospam@freemail.hu>
|
|
||||||
Cam Swords <cam.swords@gmail.com>
|
|
||||||
Chris Dickinson <christopher.s.dickinson@gmail.com>
|
|
||||||
Uli Köhler <ukoehler@btronik.de>
|
|
||||||
Charlie Somerville <charlie@charliesomerville.com>
|
|
||||||
Patrik Stutz <patrik.stutz@gmail.com>
|
|
||||||
Fedor Indutny <fedor.indutny@gmail.com>
|
|
||||||
runner <runner.mei@gmail.com>
|
|
||||||
Alexis Campailla <alexis@janeasystems.com>
|
|
||||||
David Wragg <david@wragg.org>
|
|
||||||
Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
Alex Butum <alexbutum@linux.com>
|
|
||||||
Rex Feng <rexfeng@gmail.com>
|
|
||||||
Alex Kocharin <alex@kocharin.ru>
|
|
||||||
Mark Koopman <markmontymark@yahoo.com>
|
|
||||||
Helge Heß <me@helgehess.eu>
|
|
||||||
Alexis La Goutte <alexis.lagoutte@gmail.com>
|
|
||||||
George Miroshnykov <george.miroshnykov@gmail.com>
|
|
||||||
Maciej Małecki <me@mmalecki.com>
|
|
||||||
Marc O'Morain <github.com@marcomorain.com>
|
|
||||||
Jeff Pinner <jpinner@twitter.com>
|
|
||||||
Timothy J Fontaine <tjfontaine@gmail.com>
|
|
||||||
Akagi201 <akagi201@gmail.com>
|
|
||||||
Romain Giraud <giraud.romain@gmail.com>
|
|
||||||
Jay Satiro <raysatiro@yahoo.com>
|
|
||||||
Arne Steen <Arne.Steen@gmx.de>
|
|
||||||
Kjell Schubert <kjell.schubert@gmail.com>
|
|
||||||
Olivier Mengué <dolmen@cpan.org>
|
|
19
src/3rdparty/http-parser/LICENSE-MIT
vendored
19
src/3rdparty/http-parser/LICENSE-MIT
vendored
|
@ -1,19 +0,0 @@
|
||||||
Copyright Joyent, Inc. and other Node contributors.
|
|
||||||
|
|
||||||
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.
|
|
246
src/3rdparty/http-parser/README.md
vendored
246
src/3rdparty/http-parser/README.md
vendored
|
@ -1,246 +0,0 @@
|
||||||
HTTP Parser
|
|
||||||
===========
|
|
||||||
|
|
||||||
[](https://travis-ci.org/nodejs/http-parser)
|
|
||||||
|
|
||||||
This is a parser for HTTP messages written in C. It parses both requests and
|
|
||||||
responses. The parser is designed to be used in performance HTTP
|
|
||||||
applications. It does not make any syscalls nor allocations, it does not
|
|
||||||
buffer data, it can be interrupted at anytime. Depending on your
|
|
||||||
architecture, it only requires about 40 bytes of data per message
|
|
||||||
stream (in a web server that is per connection).
|
|
||||||
|
|
||||||
Features:
|
|
||||||
|
|
||||||
* No dependencies
|
|
||||||
* Handles persistent streams (keep-alive).
|
|
||||||
* Decodes chunked encoding.
|
|
||||||
* Upgrade support
|
|
||||||
* Defends against buffer overflow attacks.
|
|
||||||
|
|
||||||
The parser extracts the following information from HTTP messages:
|
|
||||||
|
|
||||||
* Header fields and values
|
|
||||||
* Content-Length
|
|
||||||
* Request method
|
|
||||||
* Response status code
|
|
||||||
* Transfer-Encoding
|
|
||||||
* HTTP version
|
|
||||||
* Request URL
|
|
||||||
* Message body
|
|
||||||
|
|
||||||
|
|
||||||
Usage
|
|
||||||
-----
|
|
||||||
|
|
||||||
One `http_parser` object is used per TCP connection. Initialize the struct
|
|
||||||
using `http_parser_init()` and set the callbacks. That might look something
|
|
||||||
like this for a request parser:
|
|
||||||
```c
|
|
||||||
http_parser_settings settings;
|
|
||||||
settings.on_url = my_url_callback;
|
|
||||||
settings.on_header_field = my_header_field_callback;
|
|
||||||
/* ... */
|
|
||||||
|
|
||||||
http_parser *parser = malloc(sizeof(http_parser));
|
|
||||||
http_parser_init(parser, HTTP_REQUEST);
|
|
||||||
parser->data = my_socket;
|
|
||||||
```
|
|
||||||
|
|
||||||
When data is received on the socket execute the parser and check for errors.
|
|
||||||
|
|
||||||
```c
|
|
||||||
size_t len = 80*1024, nparsed;
|
|
||||||
char buf[len];
|
|
||||||
ssize_t recved;
|
|
||||||
|
|
||||||
recved = recv(fd, buf, len, 0);
|
|
||||||
|
|
||||||
if (recved < 0) {
|
|
||||||
/* Handle error. */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start up / continue the parser.
|
|
||||||
* Note we pass recved==0 to signal that EOF has been received.
|
|
||||||
*/
|
|
||||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
|
||||||
|
|
||||||
if (parser->upgrade) {
|
|
||||||
/* handle new protocol */
|
|
||||||
} else if (nparsed != recved) {
|
|
||||||
/* Handle error. Usually just close the connection. */
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`http_parser` needs to know where the end of the stream is. For example, sometimes
|
|
||||||
servers send responses without Content-Length and expect the client to
|
|
||||||
consume input (for the body) until EOF. To tell `http_parser` about EOF, give
|
|
||||||
`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors
|
|
||||||
can still be encountered during an EOF, so one must still be prepared
|
|
||||||
to receive them.
|
|
||||||
|
|
||||||
Scalar valued message information such as `status_code`, `method`, and the
|
|
||||||
HTTP version are stored in the parser structure. This data is only
|
|
||||||
temporally stored in `http_parser` and gets reset on each new message. If
|
|
||||||
this information is needed later, copy it out of the structure during the
|
|
||||||
`headers_complete` callback.
|
|
||||||
|
|
||||||
The parser decodes the transfer-encoding for both requests and responses
|
|
||||||
transparently. That is, a chunked encoding is decoded before being sent to
|
|
||||||
the on_body callback.
|
|
||||||
|
|
||||||
|
|
||||||
The Special Problem of Upgrade
|
|
||||||
------------------------------
|
|
||||||
|
|
||||||
`http_parser` supports upgrading the connection to a different protocol. An
|
|
||||||
increasingly common example of this is the WebSocket protocol which sends
|
|
||||||
a request like
|
|
||||||
|
|
||||||
GET /demo HTTP/1.1
|
|
||||||
Upgrade: WebSocket
|
|
||||||
Connection: Upgrade
|
|
||||||
Host: example.com
|
|
||||||
Origin: http://example.com
|
|
||||||
WebSocket-Protocol: sample
|
|
||||||
|
|
||||||
followed by non-HTTP data.
|
|
||||||
|
|
||||||
(See [RFC6455](https://tools.ietf.org/html/rfc6455) for more information the
|
|
||||||
WebSocket protocol.)
|
|
||||||
|
|
||||||
To support this, the parser will treat this as a normal HTTP message without a
|
|
||||||
body, issuing both on_headers_complete and on_message_complete callbacks. However
|
|
||||||
http_parser_execute() will stop parsing at the end of the headers and return.
|
|
||||||
|
|
||||||
The user is expected to check if `parser->upgrade` has been set to 1 after
|
|
||||||
`http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied
|
|
||||||
offset by the return value of `http_parser_execute()`.
|
|
||||||
|
|
||||||
|
|
||||||
Callbacks
|
|
||||||
---------
|
|
||||||
|
|
||||||
During the `http_parser_execute()` call, the callbacks set in
|
|
||||||
`http_parser_settings` will be executed. The parser maintains state and
|
|
||||||
never looks behind, so buffering the data is not necessary. If you need to
|
|
||||||
save certain data for later usage, you can do that from the callbacks.
|
|
||||||
|
|
||||||
There are two types of callbacks:
|
|
||||||
|
|
||||||
* notification `typedef int (*http_cb) (http_parser*);`
|
|
||||||
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
|
|
||||||
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
|
|
||||||
Callbacks: (requests only) on_url,
|
|
||||||
(common) on_header_field, on_header_value, on_body;
|
|
||||||
|
|
||||||
Callbacks must return 0 on success. Returning a non-zero value indicates
|
|
||||||
error to the parser, making it exit immediately.
|
|
||||||
|
|
||||||
For cases where it is necessary to pass local information to/from a callback,
|
|
||||||
the `http_parser` object's `data` field can be used.
|
|
||||||
An example of such a case is when using threads to handle a socket connection,
|
|
||||||
parse a request, and then give a response over that socket. By instantiation
|
|
||||||
of a thread-local struct containing relevant data (e.g. accepted socket,
|
|
||||||
allocated memory for callbacks to write into, etc), a parser's callbacks are
|
|
||||||
able to communicate data between the scope of the thread and the scope of the
|
|
||||||
callback in a threadsafe manner. This allows `http_parser` to be used in
|
|
||||||
multi-threaded contexts.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```c
|
|
||||||
typedef struct {
|
|
||||||
socket_t sock;
|
|
||||||
void* buffer;
|
|
||||||
int buf_len;
|
|
||||||
} custom_data_t;
|
|
||||||
|
|
||||||
|
|
||||||
int my_url_callback(http_parser* parser, const char *at, size_t length) {
|
|
||||||
/* access to thread local custom_data_t struct.
|
|
||||||
Use this access save parsed data for later use into thread local
|
|
||||||
buffer, or communicate over socket
|
|
||||||
*/
|
|
||||||
parser->data;
|
|
||||||
...
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
void http_parser_thread(socket_t sock) {
|
|
||||||
int nparsed = 0;
|
|
||||||
/* allocate memory for user data */
|
|
||||||
custom_data_t *my_data = malloc(sizeof(custom_data_t));
|
|
||||||
|
|
||||||
/* some information for use by callbacks.
|
|
||||||
* achieves thread -> callback information flow */
|
|
||||||
my_data->sock = sock;
|
|
||||||
|
|
||||||
/* instantiate a thread-local parser */
|
|
||||||
http_parser *parser = malloc(sizeof(http_parser));
|
|
||||||
http_parser_init(parser, HTTP_REQUEST); /* initialise parser */
|
|
||||||
/* this custom data reference is accessible through the reference to the
|
|
||||||
parser supplied to callback functions */
|
|
||||||
parser->data = my_data;
|
|
||||||
|
|
||||||
http_parser_settings settings; /* set up callbacks */
|
|
||||||
settings.on_url = my_url_callback;
|
|
||||||
|
|
||||||
/* execute parser */
|
|
||||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
|
||||||
|
|
||||||
...
|
|
||||||
/* parsed information copied from callback.
|
|
||||||
can now perform action on data copied into thread-local memory from callbacks.
|
|
||||||
achieves callback -> thread information flow */
|
|
||||||
my_data->buffer;
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
In case you parse HTTP message in chunks (i.e. `read()` request line
|
|
||||||
from socket, parse, read half headers, parse, etc) your data callbacks
|
|
||||||
may be called more than once. `http_parser` guarantees that data pointer is only
|
|
||||||
valid for the lifetime of callback. You can also `read()` into a heap allocated
|
|
||||||
buffer to avoid copying memory around if this fits your application.
|
|
||||||
|
|
||||||
Reading headers may be a tricky task if you read/parse headers partially.
|
|
||||||
Basically, you need to remember whether last header callback was field or value
|
|
||||||
and apply the following logic:
|
|
||||||
|
|
||||||
(on_header_field and on_header_value shortened to on_h_*)
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| State (prev. callback) | Callback | Description/action |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
|
|
||||||
| | | into it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| value | on_h_field | New header started. |
|
|
||||||
| | | Copy current name,value buffers to headers |
|
|
||||||
| | | list and allocate new buffer for new name |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| field | on_h_field | Previous name continues. Reallocate name |
|
|
||||||
| | | buffer and append callback data to it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| field | on_h_value | Value for current header started. Allocate |
|
|
||||||
| | | new buffer and copy callback data to it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| value | on_h_value | Value continues. Reallocate value buffer |
|
|
||||||
| | | and append callback data to it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Parsing URLs
|
|
||||||
------------
|
|
||||||
|
|
||||||
A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`.
|
|
||||||
Users of this library may wish to use it to parse URLs constructed from
|
|
||||||
consecutive `on_url` callbacks.
|
|
||||||
|
|
||||||
See examples of reading in headers:
|
|
||||||
|
|
||||||
* [partial example](http://gist.github.com/155877) in C
|
|
||||||
* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C
|
|
||||||
* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript
|
|
2565
src/3rdparty/http-parser/http_parser.c
vendored
2565
src/3rdparty/http-parser/http_parser.c
vendored
File diff suppressed because it is too large
Load diff
442
src/3rdparty/http-parser/http_parser.h
vendored
442
src/3rdparty/http-parser/http_parser.h
vendored
|
@ -1,442 +0,0 @@
|
||||||
/* 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
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Also update SONAME in the Makefile whenever you change these. */
|
|
||||||
#define HTTP_PARSER_VERSION_MAJOR 2
|
|
||||||
#define HTTP_PARSER_VERSION_MINOR 9
|
|
||||||
#define HTTP_PARSER_VERSION_PATCH 3
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#if defined(_WIN32) && !defined(__MINGW32__) && \
|
|
||||||
(!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
|
|
||||||
#include <BaseTsd.h>
|
|
||||||
typedef __int8 int8_t;
|
|
||||||
typedef unsigned __int8 uint8_t;
|
|
||||||
typedef __int16 int16_t;
|
|
||||||
typedef unsigned __int16 uint16_t;
|
|
||||||
typedef __int32 int32_t;
|
|
||||||
typedef unsigned __int32 uint32_t;
|
|
||||||
typedef __int64 int64_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
#else
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
|
||||||
* faster
|
|
||||||
*/
|
|
||||||
#ifndef HTTP_PARSER_STRICT
|
|
||||||
# define HTTP_PARSER_STRICT 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Maximium header size allowed. If the macro is not defined
|
|
||||||
* before including this header then the default is used. To
|
|
||||||
* change the maximum header size, define the macro in the build
|
|
||||||
* environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove
|
|
||||||
* the effective limit on the size of the header, define the macro
|
|
||||||
* to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff)
|
|
||||||
*/
|
|
||||||
#ifndef HTTP_MAX_HEADER_SIZE
|
|
||||||
# define HTTP_MAX_HEADER_SIZE (80*1024)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct http_parser http_parser;
|
|
||||||
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.
|
|
||||||
*
|
|
||||||
* Returning `2` from on_headers_complete will tell parser that it should not
|
|
||||||
* expect neither a body nor any futher responses on this connection. This is
|
|
||||||
* useful for handling responses to a CONNECT request which may not contain
|
|
||||||
* `Upgrade` or `Connection: upgrade` headers.
|
|
||||||
*
|
|
||||||
* http_data_cb does not return data chunks. It will be called arbitrarily
|
|
||||||
* 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*);
|
|
||||||
|
|
||||||
|
|
||||||
/* Status Codes */
|
|
||||||
#define HTTP_STATUS_MAP(XX) \
|
|
||||||
XX(100, CONTINUE, Continue) \
|
|
||||||
XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
|
|
||||||
XX(102, PROCESSING, Processing) \
|
|
||||||
XX(200, OK, OK) \
|
|
||||||
XX(201, CREATED, Created) \
|
|
||||||
XX(202, ACCEPTED, Accepted) \
|
|
||||||
XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
|
|
||||||
XX(204, NO_CONTENT, No Content) \
|
|
||||||
XX(205, RESET_CONTENT, Reset Content) \
|
|
||||||
XX(206, PARTIAL_CONTENT, Partial Content) \
|
|
||||||
XX(207, MULTI_STATUS, Multi-Status) \
|
|
||||||
XX(208, ALREADY_REPORTED, Already Reported) \
|
|
||||||
XX(226, IM_USED, IM Used) \
|
|
||||||
XX(300, MULTIPLE_CHOICES, Multiple Choices) \
|
|
||||||
XX(301, MOVED_PERMANENTLY, Moved Permanently) \
|
|
||||||
XX(302, FOUND, Found) \
|
|
||||||
XX(303, SEE_OTHER, See Other) \
|
|
||||||
XX(304, NOT_MODIFIED, Not Modified) \
|
|
||||||
XX(305, USE_PROXY, Use Proxy) \
|
|
||||||
XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
|
|
||||||
XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
|
|
||||||
XX(400, BAD_REQUEST, Bad Request) \
|
|
||||||
XX(401, UNAUTHORIZED, Unauthorized) \
|
|
||||||
XX(402, PAYMENT_REQUIRED, Payment Required) \
|
|
||||||
XX(403, FORBIDDEN, Forbidden) \
|
|
||||||
XX(404, NOT_FOUND, Not Found) \
|
|
||||||
XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
|
|
||||||
XX(406, NOT_ACCEPTABLE, Not Acceptable) \
|
|
||||||
XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
|
|
||||||
XX(408, REQUEST_TIMEOUT, Request Timeout) \
|
|
||||||
XX(409, CONFLICT, Conflict) \
|
|
||||||
XX(410, GONE, Gone) \
|
|
||||||
XX(411, LENGTH_REQUIRED, Length Required) \
|
|
||||||
XX(412, PRECONDITION_FAILED, Precondition Failed) \
|
|
||||||
XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
|
|
||||||
XX(414, URI_TOO_LONG, URI Too Long) \
|
|
||||||
XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
|
|
||||||
XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
|
|
||||||
XX(417, EXPECTATION_FAILED, Expectation Failed) \
|
|
||||||
XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
|
|
||||||
XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
|
|
||||||
XX(423, LOCKED, Locked) \
|
|
||||||
XX(424, FAILED_DEPENDENCY, Failed Dependency) \
|
|
||||||
XX(426, UPGRADE_REQUIRED, Upgrade Required) \
|
|
||||||
XX(428, PRECONDITION_REQUIRED, Precondition Required) \
|
|
||||||
XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
|
|
||||||
XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
|
|
||||||
XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
|
|
||||||
XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
|
|
||||||
XX(501, NOT_IMPLEMENTED, Not Implemented) \
|
|
||||||
XX(502, BAD_GATEWAY, Bad Gateway) \
|
|
||||||
XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
|
|
||||||
XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
|
|
||||||
XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
|
|
||||||
XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
|
|
||||||
XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
|
|
||||||
XX(508, LOOP_DETECTED, Loop Detected) \
|
|
||||||
XX(510, NOT_EXTENDED, Not Extended) \
|
|
||||||
XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
|
|
||||||
|
|
||||||
enum http_status
|
|
||||||
{
|
|
||||||
#define XX(num, name, string) HTTP_STATUS_##name = num,
|
|
||||||
HTTP_STATUS_MAP(XX)
|
|
||||||
#undef XX
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Request Methods */
|
|
||||||
#define HTTP_METHOD_MAP(XX) \
|
|
||||||
XX(0, DELETE, DELETE) \
|
|
||||||
XX(1, GET, GET) \
|
|
||||||
XX(2, HEAD, HEAD) \
|
|
||||||
XX(3, POST, POST) \
|
|
||||||
XX(4, PUT, PUT) \
|
|
||||||
/* pathological */ \
|
|
||||||
XX(5, CONNECT, CONNECT) \
|
|
||||||
XX(6, OPTIONS, OPTIONS) \
|
|
||||||
XX(7, TRACE, TRACE) \
|
|
||||||
/* WebDAV */ \
|
|
||||||
XX(8, COPY, COPY) \
|
|
||||||
XX(9, LOCK, LOCK) \
|
|
||||||
XX(10, MKCOL, MKCOL) \
|
|
||||||
XX(11, MOVE, MOVE) \
|
|
||||||
XX(12, PROPFIND, PROPFIND) \
|
|
||||||
XX(13, PROPPATCH, PROPPATCH) \
|
|
||||||
XX(14, SEARCH, SEARCH) \
|
|
||||||
XX(15, UNLOCK, UNLOCK) \
|
|
||||||
XX(16, BIND, BIND) \
|
|
||||||
XX(17, REBIND, REBIND) \
|
|
||||||
XX(18, UNBIND, UNBIND) \
|
|
||||||
XX(19, ACL, ACL) \
|
|
||||||
/* subversion */ \
|
|
||||||
XX(20, REPORT, REPORT) \
|
|
||||||
XX(21, MKACTIVITY, MKACTIVITY) \
|
|
||||||
XX(22, CHECKOUT, CHECKOUT) \
|
|
||||||
XX(23, MERGE, MERGE) \
|
|
||||||
/* upnp */ \
|
|
||||||
XX(24, MSEARCH, M-SEARCH) \
|
|
||||||
XX(25, NOTIFY, NOTIFY) \
|
|
||||||
XX(26, SUBSCRIBE, SUBSCRIBE) \
|
|
||||||
XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
|
|
||||||
/* RFC-5789 */ \
|
|
||||||
XX(28, PATCH, PATCH) \
|
|
||||||
XX(29, PURGE, PURGE) \
|
|
||||||
/* CalDAV */ \
|
|
||||||
XX(30, MKCALENDAR, MKCALENDAR) \
|
|
||||||
/* RFC-2068, section 19.6.1.2 */ \
|
|
||||||
XX(31, LINK, LINK) \
|
|
||||||
XX(32, UNLINK, UNLINK) \
|
|
||||||
/* icecast */ \
|
|
||||||
XX(33, SOURCE, SOURCE) \
|
|
||||||
|
|
||||||
enum http_method
|
|
||||||
{
|
|
||||||
#define XX(num, name, string) HTTP_##name = num,
|
|
||||||
HTTP_METHOD_MAP(XX)
|
|
||||||
#undef XX
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
|
|
||||||
|
|
||||||
|
|
||||||
/* Flag values for http_parser.flags field */
|
|
||||||
enum flags
|
|
||||||
{ F_CHUNKED = 1 << 0
|
|
||||||
, F_CONNECTION_KEEP_ALIVE = 1 << 1
|
|
||||||
, F_CONNECTION_CLOSE = 1 << 2
|
|
||||||
, F_CONNECTION_UPGRADE = 1 << 3
|
|
||||||
, F_TRAILING = 1 << 4
|
|
||||||
, F_UPGRADE = 1 << 5
|
|
||||||
, F_SKIPBODY = 1 << 6
|
|
||||||
, F_CONTENTLENGTH = 1 << 7
|
|
||||||
, F_TRANSFER_ENCODING = 1 << 8
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* 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") \
|
|
||||||
\
|
|
||||||
/* Callback-related errors */ \
|
|
||||||
XX(CB_message_begin, "the on_message_begin callback failed") \
|
|
||||||
XX(CB_url, "the on_url callback failed") \
|
|
||||||
XX(CB_header_field, "the on_header_field callback failed") \
|
|
||||||
XX(CB_header_value, "the on_header_value callback failed") \
|
|
||||||
XX(CB_headers_complete, "the on_headers_complete callback failed") \
|
|
||||||
XX(CB_body, "the on_body callback failed") \
|
|
||||||
XX(CB_message_complete, "the on_message_complete callback failed") \
|
|
||||||
XX(CB_status, "the on_status callback failed") \
|
|
||||||
XX(CB_chunk_header, "the on_chunk_header callback failed") \
|
|
||||||
XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
|
|
||||||
\
|
|
||||||
/* Parsing-related errors */ \
|
|
||||||
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
|
|
||||||
XX(HEADER_OVERFLOW, \
|
|
||||||
"too many header bytes seen; overflow detected") \
|
|
||||||
XX(CLOSED_CONNECTION, \
|
|
||||||
"data received after completed connection: close message") \
|
|
||||||
XX(INVALID_VERSION, "invalid HTTP version") \
|
|
||||||
XX(INVALID_STATUS, "invalid HTTP status code") \
|
|
||||||
XX(INVALID_METHOD, "invalid HTTP method") \
|
|
||||||
XX(INVALID_URL, "invalid URL") \
|
|
||||||
XX(INVALID_HOST, "invalid host") \
|
|
||||||
XX(INVALID_PORT, "invalid port") \
|
|
||||||
XX(INVALID_PATH, "invalid path") \
|
|
||||||
XX(INVALID_QUERY_STRING, "invalid query string") \
|
|
||||||
XX(INVALID_FRAGMENT, "invalid fragment") \
|
|
||||||
XX(LF_EXPECTED, "LF character expected") \
|
|
||||||
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
|
|
||||||
XX(INVALID_CONTENT_LENGTH, \
|
|
||||||
"invalid character in content-length header") \
|
|
||||||
XX(UNEXPECTED_CONTENT_LENGTH, \
|
|
||||||
"unexpected content-length header") \
|
|
||||||
XX(INVALID_CHUNK_SIZE, \
|
|
||||||
"invalid character in chunk size header") \
|
|
||||||
XX(INVALID_TRANSFER_ENCODING, \
|
|
||||||
"request has invalid transfer-encoding") \
|
|
||||||
XX(INVALID_CONSTANT, "invalid constant string") \
|
|
||||||
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
|
|
||||||
XX(STRICT, "strict mode assertion failed") \
|
|
||||||
XX(PAUSED, "parser is paused") \
|
|
||||||
XX(UNKNOWN, "an unknown error occurred")
|
|
||||||
|
|
||||||
|
|
||||||
/* Define HPE_* values for each errno value above */
|
|
||||||
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
|
|
||||||
enum http_errno {
|
|
||||||
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
|
||||||
};
|
|
||||||
#undef HTTP_ERRNO_GEN
|
|
||||||
|
|
||||||
|
|
||||||
/* Get an http_errno value from an http_parser */
|
|
||||||
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
|
|
||||||
|
|
||||||
|
|
||||||
struct http_parser {
|
|
||||||
/** PRIVATE **/
|
|
||||||
unsigned int type : 2; /* enum http_parser_type */
|
|
||||||
unsigned int state : 7; /* enum state from http_parser.c */
|
|
||||||
unsigned int header_state : 7; /* enum header_state from http_parser.c */
|
|
||||||
unsigned int index : 7; /* index into current matcher */
|
|
||||||
unsigned int lenient_http_headers : 1;
|
|
||||||
unsigned int flags : 16; /* F_* values from 'flags' enum; semi-public */
|
|
||||||
|
|
||||||
uint32_t nread; /* # bytes read in various scenarios */
|
|
||||||
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
|
|
||||||
|
|
||||||
/** READ-ONLY **/
|
|
||||||
unsigned short http_major;
|
|
||||||
unsigned short http_minor;
|
|
||||||
unsigned int status_code : 16; /* responses only */
|
|
||||||
unsigned int method : 8; /* requests only */
|
|
||||||
unsigned int 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.
|
|
||||||
*/
|
|
||||||
unsigned int upgrade : 1;
|
|
||||||
|
|
||||||
/** PUBLIC **/
|
|
||||||
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct http_parser_settings {
|
|
||||||
http_cb on_message_begin;
|
|
||||||
http_data_cb on_url;
|
|
||||||
http_data_cb on_status;
|
|
||||||
http_data_cb on_header_field;
|
|
||||||
http_data_cb on_header_value;
|
|
||||||
http_cb on_headers_complete;
|
|
||||||
http_data_cb on_body;
|
|
||||||
http_cb on_message_complete;
|
|
||||||
/* When on_chunk_header is called, the current chunk length is stored
|
|
||||||
* in parser->content_length.
|
|
||||||
*/
|
|
||||||
http_cb on_chunk_header;
|
|
||||||
http_cb on_chunk_complete;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum http_parser_url_fields
|
|
||||||
{ UF_SCHEMA = 0
|
|
||||||
, UF_HOST = 1
|
|
||||||
, UF_PORT = 2
|
|
||||||
, UF_PATH = 3
|
|
||||||
, UF_QUERY = 4
|
|
||||||
, UF_FRAGMENT = 5
|
|
||||||
, UF_USERINFO = 6
|
|
||||||
, UF_MAX = 7
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* 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 */
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint16_t off; /* Offset into buffer in which field starts */
|
|
||||||
uint16_t len; /* Length of run in buffer */
|
|
||||||
} field_data[UF_MAX];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns the library version. Bits 16-23 contain the major version number,
|
|
||||||
* bits 8-15 the minor version number and bits 0-7 the patch level.
|
|
||||||
* Usage example:
|
|
||||||
*
|
|
||||||
* unsigned long version = http_parser_version();
|
|
||||||
* unsigned major = (version >> 16) & 255;
|
|
||||||
* unsigned minor = (version >> 8) & 255;
|
|
||||||
* unsigned patch = version & 255;
|
|
||||||
* printf("http_parser v%u.%u.%u\n", major, minor, patch);
|
|
||||||
*/
|
|
||||||
unsigned long http_parser_version(void);
|
|
||||||
|
|
||||||
void http_parser_init(http_parser *parser, enum http_parser_type type);
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize http_parser_settings members to 0
|
|
||||||
*/
|
|
||||||
void http_parser_settings_init(http_parser_settings *settings);
|
|
||||||
|
|
||||||
|
|
||||||
/* Executes the parser. Returns number of parsed bytes. Sets
|
|
||||||
* `parser->http_errno` on error. */
|
|
||||||
size_t http_parser_execute(http_parser *parser,
|
|
||||||
const http_parser_settings *settings,
|
|
||||||
const char *data,
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
int http_should_keep_alive(const http_parser *parser);
|
|
||||||
|
|
||||||
/* Returns a string version of the HTTP method. */
|
|
||||||
const char *http_method_str(enum http_method m);
|
|
||||||
|
|
||||||
/* Returns a string version of the HTTP status code. */
|
|
||||||
const char *http_status_str(enum http_status s);
|
|
||||||
|
|
||||||
/* Return a string name of the given error */
|
|
||||||
const char *http_errno_name(enum http_errno err);
|
|
||||||
|
|
||||||
/* Return a string description of the given error */
|
|
||||||
const char *http_errno_description(enum http_errno err);
|
|
||||||
|
|
||||||
/* Initialize all http_parser_url members to 0 */
|
|
||||||
void http_parser_url_init(struct http_parser_url *u);
|
|
||||||
|
|
||||||
/* Parse a URL; return nonzero on failure */
|
|
||||||
int http_parser_parse_url(const char *buf, size_t buflen,
|
|
||||||
int is_connect,
|
|
||||||
struct http_parser_url *u);
|
|
||||||
|
|
||||||
/* Pause or un-pause the parser; a nonzero value pauses */
|
|
||||||
void http_parser_pause(http_parser *parser, int paused);
|
|
||||||
|
|
||||||
/* Checks if this is the final chunk of the body. */
|
|
||||||
int http_body_is_final(const http_parser *parser);
|
|
||||||
|
|
||||||
/* Change the maximum header size provided at compile time. */
|
|
||||||
void http_parser_set_max_header_size(uint32_t size);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
22
src/3rdparty/llhttp/LICENSE-MIT
vendored
Normal file
22
src/3rdparty/llhttp/LICENSE-MIT
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
This software is licensed under the MIT License.
|
||||||
|
|
||||||
|
Copyright Fedor Indutny, 2018.
|
||||||
|
|
||||||
|
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.
|
135
src/3rdparty/llhttp/README.md
vendored
Normal file
135
src/3rdparty/llhttp/README.md
vendored
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
# llhttp
|
||||||
|
[](https://github.com/nodejs/llhttp/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
|
Port of [http_parser][0] to [llparse][1].
|
||||||
|
|
||||||
|
## Why?
|
||||||
|
|
||||||
|
Let's face it, [http_parser][0] is practically unmaintainable. Even
|
||||||
|
introduction of a single new method results in a significant code churn.
|
||||||
|
|
||||||
|
This project aims to:
|
||||||
|
|
||||||
|
* Make it maintainable
|
||||||
|
* Verifiable
|
||||||
|
* Improving benchmarks where possible
|
||||||
|
|
||||||
|
More details in [Fedor Indutny's talk at JSConf EU 2019](https://youtu.be/x3k_5Mi66sY)
|
||||||
|
|
||||||
|
## How?
|
||||||
|
|
||||||
|
Over time, different approaches for improving [http_parser][0]'s code base
|
||||||
|
were tried. However, all of them failed due to resulting significant performance
|
||||||
|
degradation.
|
||||||
|
|
||||||
|
This project is a port of [http_parser][0] to TypeScript. [llparse][1] is used
|
||||||
|
to generate the output C source file, which could be compiled and
|
||||||
|
linked with the embedder's program (like [Node.js][7]).
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
So far llhttp outperforms http_parser:
|
||||||
|
|
||||||
|
| | input size | bandwidth | reqs/sec | time |
|
||||||
|
|:----------------|-----------:|-------------:|-----------:|--------:|
|
||||||
|
| **llhttp** | 8192.00 mb | 1777.24 mb/s | 3583799.39 req/sec | 4.61 s |
|
||||||
|
| **http_parser** | 8192.00 mb | 694.66 mb/s | 1406180.33 req/sec | 11.79 s |
|
||||||
|
|
||||||
|
llhttp is faster by approximately **156%**.
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
llhttp project has about 1400 lines of TypeScript code describing the parser
|
||||||
|
itself and around 450 lines of C code and headers providing the helper methods.
|
||||||
|
The whole [http_parser][0] is implemented in approximately 2500 lines of C, and
|
||||||
|
436 lines of headers.
|
||||||
|
|
||||||
|
All optimizations and multi-character matching in llhttp are generated
|
||||||
|
automatically, and thus doesn't add any extra maintenance cost. On the contrary,
|
||||||
|
most of http_parser's code is hand-optimized and unrolled. Instead describing
|
||||||
|
"how" it should parse the HTTP requests/responses, a maintainer should
|
||||||
|
implement the new features in [http_parser][0] cautiously, considering
|
||||||
|
possible performance degradation and manually optimizing the new code.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
The state machine graph is encoded explicitly in llhttp. The [llparse][1]
|
||||||
|
automatically checks the graph for absence of loops and correct reporting of the
|
||||||
|
input ranges (spans) like header names and values. In the future, additional
|
||||||
|
checks could be performed to get even stricter verification of the llhttp.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include "llhttp.h"
|
||||||
|
|
||||||
|
llhttp_t parser;
|
||||||
|
llhttp_settings_t settings;
|
||||||
|
|
||||||
|
/* Initialize user callbacks and settings */
|
||||||
|
llhttp_settings_init(&settings);
|
||||||
|
|
||||||
|
/* Set user callback */
|
||||||
|
settings.on_message_complete = handle_on_message_complete;
|
||||||
|
|
||||||
|
/* Initialize the parser in HTTP_BOTH mode, meaning that it will select between
|
||||||
|
* HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
|
||||||
|
* input.
|
||||||
|
*/
|
||||||
|
llhttp_init(&parser, HTTP_BOTH, &settings);
|
||||||
|
|
||||||
|
/* Parse request! */
|
||||||
|
const char* request = "GET / HTTP/1.1\r\n\r\n";
|
||||||
|
int request_len = strlen(request);
|
||||||
|
|
||||||
|
enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
|
||||||
|
if (err == HPE_OK) {
|
||||||
|
/* Successfully parsed! */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err),
|
||||||
|
parser.reason);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Bindings to other languages
|
||||||
|
|
||||||
|
* Python: [pallas/pyllhttp][8]
|
||||||
|
* Ruby: [metabahn/llhttp][9]
|
||||||
|
|
||||||
|
#### LICENSE
|
||||||
|
|
||||||
|
This software is licensed under the MIT License.
|
||||||
|
|
||||||
|
Copyright Fedor Indutny, 2018.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
[0]: https://github.com/nodejs/http-parser
|
||||||
|
[1]: https://github.com/nodejs/llparse
|
||||||
|
[2]: https://en.wikipedia.org/wiki/Register_allocation#Spilling
|
||||||
|
[3]: https://en.wikipedia.org/wiki/Tail_call
|
||||||
|
[4]: https://llvm.org/docs/LangRef.html
|
||||||
|
[5]: https://llvm.org/docs/LangRef.html#call-instruction
|
||||||
|
[6]: https://clang.llvm.org/
|
||||||
|
[7]: https://github.com/nodejs/node
|
||||||
|
[8]: https://github.com/pallas/pyllhttp
|
||||||
|
[9]: https://github.com/metabahn/llhttp
|
275
src/3rdparty/llhttp/api.c
vendored
Normal file
275
src/3rdparty/llhttp/api.c
vendored
Normal file
|
@ -0,0 +1,275 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "llhttp.h"
|
||||||
|
|
||||||
|
#define CALLBACK_MAYBE(PARSER, NAME, ...) \
|
||||||
|
do { \
|
||||||
|
const llhttp_settings_t* settings; \
|
||||||
|
settings = (const llhttp_settings_t*) (PARSER)->settings; \
|
||||||
|
if (settings == NULL || settings->NAME == NULL) { \
|
||||||
|
err = 0; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
err = settings->NAME(__VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
|
||||||
|
const llhttp_settings_t* settings) {
|
||||||
|
llhttp__internal_init(parser);
|
||||||
|
|
||||||
|
parser->type = type;
|
||||||
|
parser->settings = (void*) settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_reset(llhttp_t* parser) {
|
||||||
|
llhttp_type_t type = parser->type;
|
||||||
|
const llhttp_settings_t* settings = parser->settings;
|
||||||
|
void* data = parser->data;
|
||||||
|
uint8_t lenient_flags = parser->lenient_flags;
|
||||||
|
|
||||||
|
llhttp__internal_init(parser);
|
||||||
|
|
||||||
|
parser->type = type;
|
||||||
|
parser->settings = (void*) settings;
|
||||||
|
parser->data = data;
|
||||||
|
parser->lenient_flags = lenient_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) {
|
||||||
|
return llhttp__internal_execute(parser, data, data + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_settings_init(llhttp_settings_t* settings) {
|
||||||
|
memset(settings, 0, sizeof(*settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
llhttp_errno_t llhttp_finish(llhttp_t* parser) {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* We're in an error state. Don't bother doing anything. */
|
||||||
|
if (parser->error != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (parser->finish) {
|
||||||
|
case HTTP_FINISH_SAFE_WITH_CB:
|
||||||
|
CALLBACK_MAYBE(parser, on_message_complete, parser);
|
||||||
|
if (err != HPE_OK) return err;
|
||||||
|
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case HTTP_FINISH_SAFE:
|
||||||
|
return HPE_OK;
|
||||||
|
case HTTP_FINISH_UNSAFE:
|
||||||
|
parser->reason = "Invalid EOF state";
|
||||||
|
return HPE_INVALID_EOF_STATE;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_pause(llhttp_t* parser) {
|
||||||
|
if (parser->error != HPE_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->error = HPE_PAUSED;
|
||||||
|
parser->reason = "Paused";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_resume(llhttp_t* parser) {
|
||||||
|
if (parser->error != HPE_PAUSED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->error = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_resume_after_upgrade(llhttp_t* parser) {
|
||||||
|
if (parser->error != HPE_PAUSED_UPGRADE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->error = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser) {
|
||||||
|
return parser->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_get_error_reason(const llhttp_t* parser) {
|
||||||
|
return parser->reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_set_error_reason(llhttp_t* parser, const char* reason) {
|
||||||
|
parser->reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_get_error_pos(const llhttp_t* parser) {
|
||||||
|
return parser->error_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_errno_name(llhttp_errno_t err) {
|
||||||
|
#define HTTP_ERRNO_GEN(CODE, NAME, _) case HPE_##NAME: return "HPE_" #NAME;
|
||||||
|
switch (err) {
|
||||||
|
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
||||||
|
default: abort();
|
||||||
|
}
|
||||||
|
#undef HTTP_ERRNO_GEN
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_method_name(llhttp_method_t method) {
|
||||||
|
#define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING;
|
||||||
|
switch (method) {
|
||||||
|
HTTP_METHOD_MAP(HTTP_METHOD_GEN)
|
||||||
|
default: abort();
|
||||||
|
}
|
||||||
|
#undef HTTP_METHOD_GEN
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
parser->lenient_flags |= LENIENT_HEADERS;
|
||||||
|
} else {
|
||||||
|
parser->lenient_flags &= ~LENIENT_HEADERS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
|
||||||
|
} else {
|
||||||
|
parser->lenient_flags &= ~LENIENT_CHUNKED_LENGTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Callbacks */
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_message_begin, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_url, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_url_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_status, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_status_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_field, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_field_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_value, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_value_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_headers_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_message_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_body(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_body, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_chunk_header, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_chunk_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Private */
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp__debug(llhttp_t* s, const char* p, const char* endp,
|
||||||
|
const char* msg) {
|
||||||
|
if (p == endp) {
|
||||||
|
fprintf(stderr, "p=%p type=%d flags=%02x next=null debug=%s\n", s, s->type,
|
||||||
|
s->flags, msg);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "p=%p type=%d flags=%02x next=%02x debug=%s\n", s,
|
||||||
|
s->type, s->flags, *p, msg);
|
||||||
|
}
|
||||||
|
}
|
187
src/3rdparty/llhttp/api.h
vendored
Normal file
187
src/3rdparty/llhttp/api.h
vendored
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
#ifndef INCLUDE_LLHTTP_API_H_
|
||||||
|
#define INCLUDE_LLHTTP_API_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef llhttp__internal_t llhttp_t;
|
||||||
|
typedef struct llhttp_settings_s llhttp_settings_t;
|
||||||
|
|
||||||
|
typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length);
|
||||||
|
typedef int (*llhttp_cb)(llhttp_t*);
|
||||||
|
|
||||||
|
struct llhttp_settings_s {
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_begin;
|
||||||
|
|
||||||
|
llhttp_data_cb on_url;
|
||||||
|
llhttp_data_cb on_status;
|
||||||
|
llhttp_data_cb on_header_field;
|
||||||
|
llhttp_data_cb on_header_value;
|
||||||
|
|
||||||
|
/* Possible return values:
|
||||||
|
* 0 - Proceed normally
|
||||||
|
* 1 - Assume that request/response has no body, and proceed to parsing the
|
||||||
|
* next message
|
||||||
|
* 2 - Assume absence of body (as above) and make `llhttp_execute()` return
|
||||||
|
* `HPE_PAUSED_UPGRADE`
|
||||||
|
* -1 - Error
|
||||||
|
* `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_headers_complete;
|
||||||
|
|
||||||
|
llhttp_data_cb on_body;
|
||||||
|
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_complete;
|
||||||
|
|
||||||
|
/* When on_chunk_header is called, the current chunk length is stored
|
||||||
|
* in parser->content_length.
|
||||||
|
* Possible return values 0, -1, `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_chunk_header;
|
||||||
|
llhttp_cb on_chunk_complete;
|
||||||
|
|
||||||
|
llhttp_cb on_url_complete;
|
||||||
|
llhttp_cb on_status_complete;
|
||||||
|
llhttp_cb on_header_field_complete;
|
||||||
|
llhttp_cb on_header_value_complete;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize the parser with specific type and user settings.
|
||||||
|
*
|
||||||
|
* NOTE: lifetime of `settings` has to be at least the same as the lifetime of
|
||||||
|
* the `parser` here. In practice, `settings` has to be either a static
|
||||||
|
* variable or be allocated with `malloc`, `new`, etc.
|
||||||
|
*/
|
||||||
|
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
|
||||||
|
const llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Reset an already initialized parser back to the start state, preserving the
|
||||||
|
* existing parser type, callback settings, user data, and lenient flags.
|
||||||
|
*/
|
||||||
|
void llhttp_reset(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Initialize the settings object */
|
||||||
|
void llhttp_settings_init(llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Parse full or partial request/response, invoking user callbacks along the
|
||||||
|
* way.
|
||||||
|
*
|
||||||
|
* If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing
|
||||||
|
* interrupts, and such errno is returned from `llhttp_execute()`. If
|
||||||
|
* `HPE_PAUSED` was used as a errno, the execution can be resumed with
|
||||||
|
* `llhttp_resume()` call.
|
||||||
|
*
|
||||||
|
* In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE`
|
||||||
|
* is returned after fully parsing the request/response. If the user wishes to
|
||||||
|
* continue parsing, they need to invoke `llhttp_resume_after_upgrade()`.
|
||||||
|
*
|
||||||
|
* NOTE: if this function ever returns a non-pause type error, it will continue
|
||||||
|
* to return the same error upon each successive call up until `llhttp_init()`
|
||||||
|
* is called.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
|
||||||
|
|
||||||
|
/* This method should be called when the other side has no further bytes to
|
||||||
|
* send (e.g. shutdown of readable side of the TCP connection.)
|
||||||
|
*
|
||||||
|
* Requests without `Content-Length` and other messages might require treating
|
||||||
|
* all incoming bytes as the part of the body, up to the last byte of the
|
||||||
|
* connection. This method will invoke `on_message_complete()` callback if the
|
||||||
|
* request was terminated safely. Otherwise a error code would be returned.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_finish(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if the incoming message is parsed until the last byte, and has
|
||||||
|
* to be completed by calling `llhttp_finish()` on EOF
|
||||||
|
*/
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if there might be any other messages following the last that was
|
||||||
|
* successfully parsed.
|
||||||
|
*/
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
|
||||||
|
* appropriate error reason.
|
||||||
|
*
|
||||||
|
* Important: do not call this from user callbacks! User callbacks must return
|
||||||
|
* `HPE_PAUSED` if pausing is required.
|
||||||
|
*/
|
||||||
|
void llhttp_pause(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
|
||||||
|
*/
|
||||||
|
void llhttp_resume(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
|
||||||
|
*/
|
||||||
|
void llhttp_resume_after_upgrade(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the latest return error */
|
||||||
|
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the verbal explanation of the latest returned error.
|
||||||
|
*
|
||||||
|
* Note: User callback should set error reason when returning the error. See
|
||||||
|
* `llhttp_set_error_reason()` for details.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_reason(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Assign verbal description to the returned error. Must be called in user
|
||||||
|
* callbacks right before returning the errno.
|
||||||
|
*
|
||||||
|
* Note: `HPE_USER` error code might be useful in user callbacks.
|
||||||
|
*/
|
||||||
|
void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
|
||||||
|
|
||||||
|
/* Returns the pointer to the last parsed byte before the returned error. The
|
||||||
|
* pointer is relative to the `data` argument of `llhttp_execute()`.
|
||||||
|
*
|
||||||
|
* Note: this method might be useful for counting the number of parsed bytes.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_pos(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns textual name of error code */
|
||||||
|
const char* llhttp_errno_name(llhttp_errno_t err);
|
||||||
|
|
||||||
|
/* Returns textual name of HTTP method */
|
||||||
|
const char* llhttp_method_name(llhttp_method_t method);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient header value parsing (disabled by default).
|
||||||
|
*
|
||||||
|
* Lenient parsing disables header value token checks, extending llhttp's
|
||||||
|
* protocol support to highly non-compliant clients/server. No
|
||||||
|
* `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
|
||||||
|
* lenient parsing is "on".
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
|
||||||
|
* `Content-Length` headers (disabled by default).
|
||||||
|
*
|
||||||
|
* Normally `llhttp` would error when `Transfer-Encoding` is present in
|
||||||
|
* conjunction with `Content-Length`. This error is important to prevent HTTP
|
||||||
|
* request smuggling, but may be less desirable for small number of cases
|
||||||
|
* involving legacy servers.
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* INCLUDE_LLHTTP_API_H_ */
|
149
src/3rdparty/llhttp/http.c
vendored
Normal file
149
src/3rdparty/llhttp/http.c
vendored
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#ifndef LLHTTP__TEST
|
||||||
|
# include "llhttp.h"
|
||||||
|
#else
|
||||||
|
# define llhttp_t llparse_t
|
||||||
|
#endif /* */
|
||||||
|
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser);
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser);
|
||||||
|
|
||||||
|
int llhttp__before_headers_complete(llhttp_t* parser, const char* p,
|
||||||
|
const char* endp) {
|
||||||
|
/* Set this here so that on_headers_complete() callbacks can see it */
|
||||||
|
if ((parser->flags & F_UPGRADE) &&
|
||||||
|
(parser->flags & F_CONNECTION_UPGRADE)) {
|
||||||
|
/* For responses, "Upgrade: foo" and "Connection: upgrade" are
|
||||||
|
* mandatory only when it is a 101 Switching Protocols response,
|
||||||
|
* otherwise it is purely informational, to announce support.
|
||||||
|
*/
|
||||||
|
parser->upgrade =
|
||||||
|
(parser->type == HTTP_REQUEST || parser->status_code == 101);
|
||||||
|
} else {
|
||||||
|
parser->upgrade = (parser->method == HTTP_CONNECT);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return values:
|
||||||
|
* 0 - No body, `restart`, message_complete
|
||||||
|
* 1 - CONNECT request, `restart`, message_complete, and pause
|
||||||
|
* 2 - chunk_size_start
|
||||||
|
* 3 - body_identity
|
||||||
|
* 4 - body_identity_eof
|
||||||
|
* 5 - invalid transfer-encoding for request
|
||||||
|
*/
|
||||||
|
int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
|
||||||
|
const char* endp) {
|
||||||
|
int hasBody;
|
||||||
|
|
||||||
|
hasBody = parser->flags & F_CHUNKED || parser->content_length > 0;
|
||||||
|
if (parser->upgrade && (parser->method == HTTP_CONNECT ||
|
||||||
|
(parser->flags & F_SKIPBODY) || !hasBody)) {
|
||||||
|
/* Exit, the rest of the message is in a different protocol. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser->flags & F_SKIPBODY) {
|
||||||
|
return 0;
|
||||||
|
} else if (parser->flags & F_CHUNKED) {
|
||||||
|
/* chunked encoding - ignore Content-Length header, prepare for a chunk */
|
||||||
|
return 2;
|
||||||
|
} else if (parser->flags & F_TRANSFER_ENCODING) {
|
||||||
|
if (parser->type == HTTP_REQUEST &&
|
||||||
|
(parser->lenient_flags & LENIENT_CHUNKED_LENGTH) == 0) {
|
||||||
|
/* RFC 7230 3.3.3 */
|
||||||
|
|
||||||
|
/* If a Transfer-Encoding header field
|
||||||
|
* is present in a request and the chunked transfer coding is not
|
||||||
|
* the final encoding, the message body length cannot be determined
|
||||||
|
* reliably; the server MUST respond with the 400 (Bad Request)
|
||||||
|
* status code and then close the connection.
|
||||||
|
*/
|
||||||
|
return 5;
|
||||||
|
} else {
|
||||||
|
/* RFC 7230 3.3.3 */
|
||||||
|
|
||||||
|
/* If a Transfer-Encoding header field is present in a response and
|
||||||
|
* the chunked transfer coding is not the final encoding, the
|
||||||
|
* message body length is determined by reading the connection until
|
||||||
|
* it is closed by the server.
|
||||||
|
*/
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(parser->flags & F_CONTENT_LENGTH)) {
|
||||||
|
if (!llhttp_message_needs_eof(parser)) {
|
||||||
|
/* Assume content-length 0 - read the next */
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
/* Read body until EOF */
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
} else if (parser->content_length == 0) {
|
||||||
|
/* Content-Length header given but zero: Content-Length: 0\r\n */
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
/* Content-Length header given and non-zero */
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__after_message_complete(llhttp_t* parser, const char* p,
|
||||||
|
const char* endp) {
|
||||||
|
int should_keep_alive;
|
||||||
|
|
||||||
|
should_keep_alive = llhttp_should_keep_alive(parser);
|
||||||
|
parser->finish = HTTP_FINISH_SAFE;
|
||||||
|
parser->flags = 0;
|
||||||
|
|
||||||
|
/* NOTE: this is ignored in loose parsing mode */
|
||||||
|
return should_keep_alive;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser) {
|
||||||
|
if (parser->type == HTTP_REQUEST) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See RFC 2616 section 4.4 */
|
||||||
|
if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */
|
||||||
|
parser->status_code == 204 || /* No Content */
|
||||||
|
parser->status_code == 304 || /* Not Modified */
|
||||||
|
(parser->flags & F_SKIPBODY)) { /* response to a HEAD request */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RFC 7230 3.3.3, see `llhttp__after_headers_complete` */
|
||||||
|
if ((parser->flags & F_TRANSFER_ENCODING) &&
|
||||||
|
(parser->flags & F_CHUNKED) == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser->flags & (F_CHUNKED | F_CONTENT_LENGTH)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser) {
|
||||||
|
if (parser->http_major > 0 && parser->http_minor > 0) {
|
||||||
|
/* HTTP/1.1 */
|
||||||
|
if (parser->flags & F_CONNECTION_CLOSE) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* HTTP/1.0 or earlier */
|
||||||
|
if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !llhttp_message_needs_eof(parser);
|
||||||
|
}
|
14871
src/3rdparty/llhttp/llhttp.c
vendored
Normal file
14871
src/3rdparty/llhttp/llhttp.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
439
src/3rdparty/llhttp/llhttp.h
vendored
Normal file
439
src/3rdparty/llhttp/llhttp.h
vendored
Normal file
|
@ -0,0 +1,439 @@
|
||||||
|
#ifndef INCLUDE_LLHTTP_H_
|
||||||
|
#define INCLUDE_LLHTTP_H_
|
||||||
|
|
||||||
|
#define LLHTTP_VERSION_MAJOR 4
|
||||||
|
#define LLHTTP_VERSION_MINOR 0
|
||||||
|
#define LLHTTP_VERSION_PATCH 0
|
||||||
|
|
||||||
|
#ifndef LLHTTP_STRICT_MODE
|
||||||
|
# define LLHTTP_STRICT_MODE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef INCLUDE_LLHTTP_ITSELF_H_
|
||||||
|
#define INCLUDE_LLHTTP_ITSELF_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct llhttp__internal_s llhttp__internal_t;
|
||||||
|
struct llhttp__internal_s {
|
||||||
|
int32_t _index;
|
||||||
|
void* _span_pos0;
|
||||||
|
void* _span_cb0;
|
||||||
|
int32_t error;
|
||||||
|
const char* reason;
|
||||||
|
const char* error_pos;
|
||||||
|
void* data;
|
||||||
|
void* _current;
|
||||||
|
uint64_t content_length;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t method;
|
||||||
|
uint8_t http_major;
|
||||||
|
uint8_t http_minor;
|
||||||
|
uint8_t header_state;
|
||||||
|
uint8_t lenient_flags;
|
||||||
|
uint8_t upgrade;
|
||||||
|
uint8_t finish;
|
||||||
|
uint16_t flags;
|
||||||
|
uint16_t status_code;
|
||||||
|
void* settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
int llhttp__internal_init(llhttp__internal_t* s);
|
||||||
|
int llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* endp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* INCLUDE_LLHTTP_ITSELF_H_ */
|
||||||
|
|
||||||
|
#ifndef LLLLHTTP_C_HEADERS_
|
||||||
|
#define LLLLHTTP_C_HEADERS_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum llhttp_errno {
|
||||||
|
HPE_OK = 0,
|
||||||
|
HPE_INTERNAL = 1,
|
||||||
|
HPE_STRICT = 2,
|
||||||
|
HPE_LF_EXPECTED = 3,
|
||||||
|
HPE_UNEXPECTED_CONTENT_LENGTH = 4,
|
||||||
|
HPE_CLOSED_CONNECTION = 5,
|
||||||
|
HPE_INVALID_METHOD = 6,
|
||||||
|
HPE_INVALID_URL = 7,
|
||||||
|
HPE_INVALID_CONSTANT = 8,
|
||||||
|
HPE_INVALID_VERSION = 9,
|
||||||
|
HPE_INVALID_HEADER_TOKEN = 10,
|
||||||
|
HPE_INVALID_CONTENT_LENGTH = 11,
|
||||||
|
HPE_INVALID_CHUNK_SIZE = 12,
|
||||||
|
HPE_INVALID_STATUS = 13,
|
||||||
|
HPE_INVALID_EOF_STATE = 14,
|
||||||
|
HPE_INVALID_TRANSFER_ENCODING = 15,
|
||||||
|
HPE_CB_MESSAGE_BEGIN = 16,
|
||||||
|
HPE_CB_HEADERS_COMPLETE = 17,
|
||||||
|
HPE_CB_MESSAGE_COMPLETE = 18,
|
||||||
|
HPE_CB_CHUNK_HEADER = 19,
|
||||||
|
HPE_CB_CHUNK_COMPLETE = 20,
|
||||||
|
HPE_PAUSED = 21,
|
||||||
|
HPE_PAUSED_UPGRADE = 22,
|
||||||
|
HPE_USER = 23
|
||||||
|
};
|
||||||
|
typedef enum llhttp_errno llhttp_errno_t;
|
||||||
|
|
||||||
|
enum llhttp_flags {
|
||||||
|
F_CONNECTION_KEEP_ALIVE = 0x1,
|
||||||
|
F_CONNECTION_CLOSE = 0x2,
|
||||||
|
F_CONNECTION_UPGRADE = 0x4,
|
||||||
|
F_CHUNKED = 0x8,
|
||||||
|
F_UPGRADE = 0x10,
|
||||||
|
F_CONTENT_LENGTH = 0x20,
|
||||||
|
F_SKIPBODY = 0x40,
|
||||||
|
F_TRAILING = 0x80,
|
||||||
|
F_TRANSFER_ENCODING = 0x200
|
||||||
|
};
|
||||||
|
typedef enum llhttp_flags llhttp_flags_t;
|
||||||
|
|
||||||
|
enum llhttp_lenient_flags {
|
||||||
|
LENIENT_HEADERS = 0x1,
|
||||||
|
LENIENT_CHUNKED_LENGTH = 0x2
|
||||||
|
};
|
||||||
|
typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
|
||||||
|
|
||||||
|
enum llhttp_type {
|
||||||
|
HTTP_BOTH = 0,
|
||||||
|
HTTP_REQUEST = 1,
|
||||||
|
HTTP_RESPONSE = 2
|
||||||
|
};
|
||||||
|
typedef enum llhttp_type llhttp_type_t;
|
||||||
|
|
||||||
|
enum llhttp_finish {
|
||||||
|
HTTP_FINISH_SAFE = 0,
|
||||||
|
HTTP_FINISH_SAFE_WITH_CB = 1,
|
||||||
|
HTTP_FINISH_UNSAFE = 2
|
||||||
|
};
|
||||||
|
typedef enum llhttp_finish llhttp_finish_t;
|
||||||
|
|
||||||
|
enum llhttp_method {
|
||||||
|
HTTP_DELETE = 0,
|
||||||
|
HTTP_GET = 1,
|
||||||
|
HTTP_HEAD = 2,
|
||||||
|
HTTP_POST = 3,
|
||||||
|
HTTP_PUT = 4,
|
||||||
|
HTTP_CONNECT = 5,
|
||||||
|
HTTP_OPTIONS = 6,
|
||||||
|
HTTP_TRACE = 7,
|
||||||
|
HTTP_COPY = 8,
|
||||||
|
HTTP_LOCK = 9,
|
||||||
|
HTTP_MKCOL = 10,
|
||||||
|
HTTP_MOVE = 11,
|
||||||
|
HTTP_PROPFIND = 12,
|
||||||
|
HTTP_PROPPATCH = 13,
|
||||||
|
HTTP_SEARCH = 14,
|
||||||
|
HTTP_UNLOCK = 15,
|
||||||
|
HTTP_BIND = 16,
|
||||||
|
HTTP_REBIND = 17,
|
||||||
|
HTTP_UNBIND = 18,
|
||||||
|
HTTP_ACL = 19,
|
||||||
|
HTTP_REPORT = 20,
|
||||||
|
HTTP_MKACTIVITY = 21,
|
||||||
|
HTTP_CHECKOUT = 22,
|
||||||
|
HTTP_MERGE = 23,
|
||||||
|
HTTP_MSEARCH = 24,
|
||||||
|
HTTP_NOTIFY = 25,
|
||||||
|
HTTP_SUBSCRIBE = 26,
|
||||||
|
HTTP_UNSUBSCRIBE = 27,
|
||||||
|
HTTP_PATCH = 28,
|
||||||
|
HTTP_PURGE = 29,
|
||||||
|
HTTP_MKCALENDAR = 30,
|
||||||
|
HTTP_LINK = 31,
|
||||||
|
HTTP_UNLINK = 32,
|
||||||
|
HTTP_SOURCE = 33,
|
||||||
|
HTTP_PRI = 34,
|
||||||
|
HTTP_DESCRIBE = 35,
|
||||||
|
HTTP_ANNOUNCE = 36,
|
||||||
|
HTTP_SETUP = 37,
|
||||||
|
HTTP_PLAY = 38,
|
||||||
|
HTTP_PAUSE = 39,
|
||||||
|
HTTP_TEARDOWN = 40,
|
||||||
|
HTTP_GET_PARAMETER = 41,
|
||||||
|
HTTP_SET_PARAMETER = 42,
|
||||||
|
HTTP_REDIRECT = 43,
|
||||||
|
HTTP_RECORD = 44,
|
||||||
|
HTTP_FLUSH = 45
|
||||||
|
};
|
||||||
|
typedef enum llhttp_method llhttp_method_t;
|
||||||
|
|
||||||
|
#define HTTP_ERRNO_MAP(XX) \
|
||||||
|
XX(0, OK, OK) \
|
||||||
|
XX(1, INTERNAL, INTERNAL) \
|
||||||
|
XX(2, STRICT, STRICT) \
|
||||||
|
XX(3, LF_EXPECTED, LF_EXPECTED) \
|
||||||
|
XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \
|
||||||
|
XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \
|
||||||
|
XX(6, INVALID_METHOD, INVALID_METHOD) \
|
||||||
|
XX(7, INVALID_URL, INVALID_URL) \
|
||||||
|
XX(8, INVALID_CONSTANT, INVALID_CONSTANT) \
|
||||||
|
XX(9, INVALID_VERSION, INVALID_VERSION) \
|
||||||
|
XX(10, INVALID_HEADER_TOKEN, INVALID_HEADER_TOKEN) \
|
||||||
|
XX(11, INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH) \
|
||||||
|
XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \
|
||||||
|
XX(13, INVALID_STATUS, INVALID_STATUS) \
|
||||||
|
XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \
|
||||||
|
XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \
|
||||||
|
XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
|
||||||
|
XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
|
||||||
|
XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
|
||||||
|
XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
|
||||||
|
XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
|
||||||
|
XX(21, PAUSED, PAUSED) \
|
||||||
|
XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
|
||||||
|
XX(23, USER, USER) \
|
||||||
|
|
||||||
|
|
||||||
|
#define HTTP_METHOD_MAP(XX) \
|
||||||
|
XX(0, DELETE, DELETE) \
|
||||||
|
XX(1, GET, GET) \
|
||||||
|
XX(2, HEAD, HEAD) \
|
||||||
|
XX(3, POST, POST) \
|
||||||
|
XX(4, PUT, PUT) \
|
||||||
|
XX(5, CONNECT, CONNECT) \
|
||||||
|
XX(6, OPTIONS, OPTIONS) \
|
||||||
|
XX(7, TRACE, TRACE) \
|
||||||
|
XX(8, COPY, COPY) \
|
||||||
|
XX(9, LOCK, LOCK) \
|
||||||
|
XX(10, MKCOL, MKCOL) \
|
||||||
|
XX(11, MOVE, MOVE) \
|
||||||
|
XX(12, PROPFIND, PROPFIND) \
|
||||||
|
XX(13, PROPPATCH, PROPPATCH) \
|
||||||
|
XX(14, SEARCH, SEARCH) \
|
||||||
|
XX(15, UNLOCK, UNLOCK) \
|
||||||
|
XX(16, BIND, BIND) \
|
||||||
|
XX(17, REBIND, REBIND) \
|
||||||
|
XX(18, UNBIND, UNBIND) \
|
||||||
|
XX(19, ACL, ACL) \
|
||||||
|
XX(20, REPORT, REPORT) \
|
||||||
|
XX(21, MKACTIVITY, MKACTIVITY) \
|
||||||
|
XX(22, CHECKOUT, CHECKOUT) \
|
||||||
|
XX(23, MERGE, MERGE) \
|
||||||
|
XX(24, MSEARCH, M-SEARCH) \
|
||||||
|
XX(25, NOTIFY, NOTIFY) \
|
||||||
|
XX(26, SUBSCRIBE, SUBSCRIBE) \
|
||||||
|
XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||||
|
XX(28, PATCH, PATCH) \
|
||||||
|
XX(29, PURGE, PURGE) \
|
||||||
|
XX(30, MKCALENDAR, MKCALENDAR) \
|
||||||
|
XX(31, LINK, LINK) \
|
||||||
|
XX(32, UNLINK, UNLINK) \
|
||||||
|
XX(33, SOURCE, SOURCE) \
|
||||||
|
XX(34, PRI, PRI) \
|
||||||
|
XX(35, DESCRIBE, DESCRIBE) \
|
||||||
|
XX(36, ANNOUNCE, ANNOUNCE) \
|
||||||
|
XX(37, SETUP, SETUP) \
|
||||||
|
XX(38, PLAY, PLAY) \
|
||||||
|
XX(39, PAUSE, PAUSE) \
|
||||||
|
XX(40, TEARDOWN, TEARDOWN) \
|
||||||
|
XX(41, GET_PARAMETER, GET_PARAMETER) \
|
||||||
|
XX(42, SET_PARAMETER, SET_PARAMETER) \
|
||||||
|
XX(43, REDIRECT, REDIRECT) \
|
||||||
|
XX(44, RECORD, RECORD) \
|
||||||
|
XX(45, FLUSH, FLUSH) \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* LLLLHTTP_C_HEADERS_ */
|
||||||
|
|
||||||
|
#ifndef INCLUDE_LLHTTP_API_H_
|
||||||
|
#define INCLUDE_LLHTTP_API_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef llhttp__internal_t llhttp_t;
|
||||||
|
typedef struct llhttp_settings_s llhttp_settings_t;
|
||||||
|
|
||||||
|
typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length);
|
||||||
|
typedef int (*llhttp_cb)(llhttp_t*);
|
||||||
|
|
||||||
|
struct llhttp_settings_s {
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_begin;
|
||||||
|
|
||||||
|
llhttp_data_cb on_url;
|
||||||
|
llhttp_data_cb on_status;
|
||||||
|
llhttp_data_cb on_header_field;
|
||||||
|
llhttp_data_cb on_header_value;
|
||||||
|
|
||||||
|
/* Possible return values:
|
||||||
|
* 0 - Proceed normally
|
||||||
|
* 1 - Assume that request/response has no body, and proceed to parsing the
|
||||||
|
* next message
|
||||||
|
* 2 - Assume absence of body (as above) and make `llhttp_execute()` return
|
||||||
|
* `HPE_PAUSED_UPGRADE`
|
||||||
|
* -1 - Error
|
||||||
|
* `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_headers_complete;
|
||||||
|
|
||||||
|
llhttp_data_cb on_body;
|
||||||
|
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_complete;
|
||||||
|
|
||||||
|
/* When on_chunk_header is called, the current chunk length is stored
|
||||||
|
* in parser->content_length.
|
||||||
|
* Possible return values 0, -1, `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_chunk_header;
|
||||||
|
llhttp_cb on_chunk_complete;
|
||||||
|
|
||||||
|
llhttp_cb on_url_complete;
|
||||||
|
llhttp_cb on_status_complete;
|
||||||
|
llhttp_cb on_header_field_complete;
|
||||||
|
llhttp_cb on_header_value_complete;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize the parser with specific type and user settings.
|
||||||
|
*
|
||||||
|
* NOTE: lifetime of `settings` has to be at least the same as the lifetime of
|
||||||
|
* the `parser` here. In practice, `settings` has to be either a static
|
||||||
|
* variable or be allocated with `malloc`, `new`, etc.
|
||||||
|
*/
|
||||||
|
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
|
||||||
|
const llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Reset an already initialized parser back to the start state, preserving the
|
||||||
|
* existing parser type, callback settings, user data, and lenient flags.
|
||||||
|
*/
|
||||||
|
void llhttp_reset(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Initialize the settings object */
|
||||||
|
void llhttp_settings_init(llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Parse full or partial request/response, invoking user callbacks along the
|
||||||
|
* way.
|
||||||
|
*
|
||||||
|
* If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing
|
||||||
|
* interrupts, and such errno is returned from `llhttp_execute()`. If
|
||||||
|
* `HPE_PAUSED` was used as a errno, the execution can be resumed with
|
||||||
|
* `llhttp_resume()` call.
|
||||||
|
*
|
||||||
|
* In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE`
|
||||||
|
* is returned after fully parsing the request/response. If the user wishes to
|
||||||
|
* continue parsing, they need to invoke `llhttp_resume_after_upgrade()`.
|
||||||
|
*
|
||||||
|
* NOTE: if this function ever returns a non-pause type error, it will continue
|
||||||
|
* to return the same error upon each successive call up until `llhttp_init()`
|
||||||
|
* is called.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
|
||||||
|
|
||||||
|
/* This method should be called when the other side has no further bytes to
|
||||||
|
* send (e.g. shutdown of readable side of the TCP connection.)
|
||||||
|
*
|
||||||
|
* Requests without `Content-Length` and other messages might require treating
|
||||||
|
* all incoming bytes as the part of the body, up to the last byte of the
|
||||||
|
* connection. This method will invoke `on_message_complete()` callback if the
|
||||||
|
* request was terminated safely. Otherwise a error code would be returned.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_finish(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if the incoming message is parsed until the last byte, and has
|
||||||
|
* to be completed by calling `llhttp_finish()` on EOF
|
||||||
|
*/
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if there might be any other messages following the last that was
|
||||||
|
* successfully parsed.
|
||||||
|
*/
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
|
||||||
|
* appropriate error reason.
|
||||||
|
*
|
||||||
|
* Important: do not call this from user callbacks! User callbacks must return
|
||||||
|
* `HPE_PAUSED` if pausing is required.
|
||||||
|
*/
|
||||||
|
void llhttp_pause(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
|
||||||
|
*/
|
||||||
|
void llhttp_resume(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
|
||||||
|
*/
|
||||||
|
void llhttp_resume_after_upgrade(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the latest return error */
|
||||||
|
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the verbal explanation of the latest returned error.
|
||||||
|
*
|
||||||
|
* Note: User callback should set error reason when returning the error. See
|
||||||
|
* `llhttp_set_error_reason()` for details.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_reason(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Assign verbal description to the returned error. Must be called in user
|
||||||
|
* callbacks right before returning the errno.
|
||||||
|
*
|
||||||
|
* Note: `HPE_USER` error code might be useful in user callbacks.
|
||||||
|
*/
|
||||||
|
void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
|
||||||
|
|
||||||
|
/* Returns the pointer to the last parsed byte before the returned error. The
|
||||||
|
* pointer is relative to the `data` argument of `llhttp_execute()`.
|
||||||
|
*
|
||||||
|
* Note: this method might be useful for counting the number of parsed bytes.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_pos(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns textual name of error code */
|
||||||
|
const char* llhttp_errno_name(llhttp_errno_t err);
|
||||||
|
|
||||||
|
/* Returns textual name of HTTP method */
|
||||||
|
const char* llhttp_method_name(llhttp_method_t method);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient header value parsing (disabled by default).
|
||||||
|
*
|
||||||
|
* Lenient parsing disables header value token checks, extending llhttp's
|
||||||
|
* protocol support to highly non-compliant clients/server. No
|
||||||
|
* `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
|
||||||
|
* lenient parsing is "on".
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
|
||||||
|
* `Content-Length` headers (disabled by default).
|
||||||
|
*
|
||||||
|
* Normally `llhttp` would error when `Transfer-Encoding` is present in
|
||||||
|
* conjunction with `Content-Length`. This error is important to prevent HTTP
|
||||||
|
* request smuggling, but may be less desirable for small number of cases
|
||||||
|
* involving legacy servers.
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* INCLUDE_LLHTTP_API_H_ */
|
||||||
|
|
||||||
|
#endif /* INCLUDE_LLHTTP_H_ */
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/Api.h"
|
#include "base/api/Api.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "base/api/interfaces/IApiListener.h"
|
#include "base/api/interfaces/IApiListener.h"
|
||||||
#include "base/api/requests/HttpApiRequest.h"
|
#include "base/api/requests/HttpApiRequest.h"
|
||||||
#include "base/crypto/keccak.h"
|
#include "base/crypto/keccak.h"
|
||||||
|
@ -186,7 +185,7 @@ void xmrig::Api::exec(IApiRequest &request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request.done(request.isNew() ? HTTP_STATUS_NOT_FOUND : HTTP_STATUS_OK);
|
request.done(request.isNew() ? 404 : 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -22,9 +16,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/Httpd.h"
|
#include "base/api/Httpd.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/api/Api.h"
|
#include "base/api/Api.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/http/HttpApiResponse.h"
|
#include "base/net/http/HttpApiResponse.h"
|
||||||
|
@ -155,25 +148,25 @@ void xmrig::Httpd::onHttpData(const HttpData &data)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
return HttpResponse(data.id(), HTTP_STATUS_NOT_FOUND).end();
|
return HttpResponse(data.id(), 404 /* NOT_FOUND */).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.method > 4) {
|
if (data.method > 4) {
|
||||||
return HttpApiResponse(data.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
|
return HttpApiResponse(data.id(), 405 /* METHOD_NOT_ALLOWED */).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int status = auth(data);
|
const int status = auth(data);
|
||||||
if (status != HTTP_STATUS_OK) {
|
if (status != 200) {
|
||||||
return HttpApiResponse(data.id(), status).end();
|
return HttpApiResponse(data.id(), status).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.method != HTTP_GET) {
|
if (data.method != HTTP_GET) {
|
||||||
if (m_base->config()->http().isRestricted()) {
|
if (m_base->config()->http().isRestricted()) {
|
||||||
return HttpApiResponse(data.id(), HTTP_STATUS_FORBIDDEN).end();
|
return HttpApiResponse(data.id(), 403 /* FORBIDDEN */).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) {
|
if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) {
|
||||||
return HttpApiResponse(data.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end();
|
return HttpApiResponse(data.id(), 415 /* UNSUPPORTED_MEDIA_TYPE */).end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,19 +179,19 @@ int xmrig::Httpd::auth(const HttpData &req) const
|
||||||
const Http &config = m_base->config()->http();
|
const Http &config = m_base->config()->http();
|
||||||
|
|
||||||
if (!req.headers.count(kAuthorization)) {
|
if (!req.headers.count(kAuthorization)) {
|
||||||
return config.isAuthRequired() ? HTTP_STATUS_UNAUTHORIZED : HTTP_STATUS_OK;
|
return config.isAuthRequired() ? 401 /* UNAUTHORIZED */ : 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.token().isNull()) {
|
if (config.token().isNull()) {
|
||||||
return HTTP_STATUS_UNAUTHORIZED;
|
return 401 /* UNAUTHORIZED */;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &token = req.headers.at(kAuthorization);
|
const std::string &token = req.headers.at(kAuthorization);
|
||||||
const size_t size = token.size();
|
const size_t size = token.size();
|
||||||
|
|
||||||
if (token.size() < 8 || config.token().size() != size - 7 || memcmp("Bearer ", token.c_str(), 7) != 0) {
|
if (token.size() < 8 || config.token().size() != size - 7 || memcmp("Bearer ", token.c_str(), 7) != 0) {
|
||||||
return HTTP_STATUS_FORBIDDEN;
|
return 403 /* FORBIDDEN */;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strncmp(config.token().data(), token.c_str() + 7, config.token().size()) == 0 ? HTTP_STATUS_OK : HTTP_STATUS_FORBIDDEN;
|
return strncmp(config.token().data(), token.c_str() + 7, config.token().size()) == 0 ? 200 : 403 /* FORBIDDEN */;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -24,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/requests/HttpApiRequest.h"
|
#include "base/api/requests/HttpApiRequest.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
|
@ -53,8 +47,8 @@ static inline const char *rpcError(int code) {
|
||||||
return "Invalid params";
|
return "Invalid params";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code >= HTTP_STATUS_BAD_REQUEST && code <= HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED) {
|
if (code >= 400 && code < 600) {
|
||||||
return http_status_str(static_cast<http_status>(code));
|
return HttpData::statusName(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Internal error";
|
return "Internal error";
|
||||||
|
@ -155,10 +149,10 @@ void xmrig::HttpApiRequest::done(int status)
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
auto &allocator = doc().GetAllocator();
|
auto &allocator = doc().GetAllocator();
|
||||||
|
|
||||||
m_res.setStatus(HTTP_STATUS_OK);
|
m_res.setStatus(200);
|
||||||
|
|
||||||
if (status != HTTP_STATUS_OK) {
|
if (status != 200) {
|
||||||
setRpcError(status == HTTP_STATUS_NOT_FOUND ? RPC_METHOD_NOT_FOUND : status);
|
setRpcError(status == 404 /* NOT_FOUND */ ? RPC_METHOD_NOT_FOUND : status);
|
||||||
}
|
}
|
||||||
else if (!reply().HasMember(kResult)) {
|
else if (!reply().HasMember(kResult)) {
|
||||||
Value result(kObjectType);
|
Value result(kObjectType);
|
||||||
|
@ -205,6 +199,6 @@ void xmrig::HttpApiRequest::rpcDone(const char *key, rapidjson::Value &value)
|
||||||
reply().AddMember("jsonrpc", "2.0", allocator);
|
reply().AddMember("jsonrpc", "2.0", allocator);
|
||||||
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
|
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
|
||||||
|
|
||||||
m_res.setStatus(HTTP_STATUS_OK);
|
m_res.setStatus(200);
|
||||||
m_res.end();
|
m_res.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -160,7 +160,7 @@ endif()
|
||||||
|
|
||||||
if (WITH_HTTP)
|
if (WITH_HTTP)
|
||||||
set(HEADERS_BASE_HTTP
|
set(HEADERS_BASE_HTTP
|
||||||
src/3rdparty/http-parser/http_parser.h
|
src/3rdparty/llhttp/llhttp.h
|
||||||
src/base/api/Api.h
|
src/base/api/Api.h
|
||||||
src/base/api/Httpd.h
|
src/base/api/Httpd.h
|
||||||
src/base/api/interfaces/IApiRequest.h
|
src/base/api/interfaces/IApiRequest.h
|
||||||
|
@ -181,7 +181,9 @@ if (WITH_HTTP)
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES_BASE_HTTP
|
set(SOURCES_BASE_HTTP
|
||||||
src/3rdparty/http-parser/http_parser.c
|
src/3rdparty/llhttp/llhttp.c
|
||||||
|
src/3rdparty/llhttp/api.c
|
||||||
|
src/3rdparty/llhttp/http.c
|
||||||
src/base/api/Api.cpp
|
src/base/api/Api.cpp
|
||||||
src/base/api/Httpd.cpp
|
src/base/api/Httpd.cpp
|
||||||
src/base/api/requests/ApiRequest.cpp
|
src/base/api/requests/ApiRequest.cpp
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
|
xmrig::FetchRequest::FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
|
||||||
quiet(quiet),
|
quiet(quiet),
|
||||||
tls(tls),
|
tls(tls),
|
||||||
method(method),
|
method(method),
|
||||||
|
@ -44,7 +44,7 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
|
xmrig::FetchRequest::FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
|
||||||
quiet(quiet),
|
quiet(quiet),
|
||||||
tls(tls),
|
tls(tls),
|
||||||
method(method),
|
method(method),
|
||||||
|
@ -99,7 +99,7 @@ void xmrig::fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttp
|
||||||
{
|
{
|
||||||
# ifdef APP_DEBUG
|
# ifdef APP_DEBUG
|
||||||
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||||
req.tls ? "s" : "", req.host.data(), req.port, http_method_str(req.method), req.path.data(), req.body.size());
|
req.tls ? "s" : "", req.host.data(), req.port, llhttp_method_name(req.method), req.path.data(), req.body.size());
|
||||||
|
|
||||||
if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) {
|
if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) {
|
||||||
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast<int>(req.body.size()), req.body.c_str());
|
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast<int>(req.body.size()), req.body.c_str());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
#define XMRIG_FETCH_H
|
#define XMRIG_FETCH_H
|
||||||
|
|
||||||
|
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "3rdparty/rapidjson/fwd.h"
|
#include "3rdparty/rapidjson/fwd.h"
|
||||||
#include "base/tools/String.h"
|
#include "base/tools/String.h"
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ class FetchRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FetchRequest() = default;
|
FetchRequest() = default;
|
||||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
|
FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
|
||||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
|
FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
|
||||||
|
|
||||||
void setBody(const char *data, size_t size, const char *contentType = nullptr);
|
void setBody(const char *data, size_t size, const char *contentType = nullptr);
|
||||||
void setBody(const rapidjson::Value &value);
|
void setBody(const rapidjson::Value &value);
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool tls = false;
|
bool tls = false;
|
||||||
http_method method = HTTP_GET;
|
llhttp_method method = HTTP_GET;
|
||||||
std::map<const std::string, const std::string> headers;
|
std::map<const std::string, const std::string> headers;
|
||||||
std::string body;
|
std::string body;
|
||||||
String fingerprint;
|
String fingerprint;
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,7 +19,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpApiResponse.h"
|
#include "base/net/http/HttpApiResponse.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "3rdparty/rapidjson/prettywriter.h"
|
#include "3rdparty/rapidjson/prettywriter.h"
|
||||||
#include "3rdparty/rapidjson/stringbuffer.h"
|
#include "3rdparty/rapidjson/stringbuffer.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
|
@ -68,7 +61,7 @@ void xmrig::HttpApiResponse::end()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_doc.HasMember(kError)) {
|
if (!m_doc.HasMember(kError)) {
|
||||||
m_doc.AddMember(StringRef(kError), StringRef(http_status_str(static_cast<http_status>(statusCode()))), m_doc.GetAllocator());
|
m_doc.AddMember(StringRef(kError), StringRef(HttpData::statusName(statusCode())), m_doc.GetAllocator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,7 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_HTTPAPIRESPONSE_H
|
#ifndef XMRIG_HTTPAPIRESPONSE_H
|
||||||
#define XMRIG_HTTPAPIRESPONSE_H
|
#define XMRIG_HTTPAPIRESPONSE_H
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpClient.h"
|
#include "base/net/http/HttpClient.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/Platform.h"
|
#include "base/kernel/Platform.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
|
@ -102,7 +102,7 @@ void xmrig::HttpClient::handshake()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << http_method_str(static_cast<http_method>(method)) << " " << url << " HTTP/1.1" << kCRLF;
|
ss << llhttp_method_name(static_cast<llhttp_method>(method)) << " " << url << " HTTP/1.1" << kCRLF;
|
||||||
|
|
||||||
for (auto &header : headers) {
|
for (auto &header : headers) {
|
||||||
ss << header.first << ": " << header.second << kCRLF;
|
ss << header.first << ": " << header.second << kCRLF;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpContext.h"
|
#include "base/net/http/HttpContext.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/kernel/interfaces/IHttpListener.h"
|
#include "base/kernel/interfaces/IHttpListener.h"
|
||||||
#include "base/tools/Baton.h"
|
#include "base/tools/Baton.h"
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
static http_parser_settings http_settings;
|
static llhttp_settings_t http_settings;
|
||||||
static std::map<uint64_t, HttpContext *> storage;
|
static std::map<uint64_t, HttpContext *> storage;
|
||||||
static uint64_t SEQUENCE = 0;
|
static uint64_t SEQUENCE = 0;
|
||||||
|
|
||||||
|
@ -78,13 +78,13 @@ xmrig::HttpContext::HttpContext(int parser_type, const std::weak_ptr<IHttpListen
|
||||||
{
|
{
|
||||||
storage[id()] = this;
|
storage[id()] = this;
|
||||||
|
|
||||||
m_parser = new http_parser;
|
m_parser = new llhttp_t;
|
||||||
m_tcp = new uv_tcp_t;
|
m_tcp = new uv_tcp_t;
|
||||||
|
|
||||||
uv_tcp_init(uv_default_loop(), m_tcp);
|
uv_tcp_init(uv_default_loop(), m_tcp);
|
||||||
uv_tcp_nodelay(m_tcp, 1);
|
uv_tcp_nodelay(m_tcp, 1);
|
||||||
|
|
||||||
http_parser_init(m_parser, static_cast<http_parser_type>(parser_type));
|
llhttp_init(m_parser, static_cast<llhttp_type_t>(parser_type), &http_settings);
|
||||||
|
|
||||||
m_parser->data = m_tcp->data = this;
|
m_parser->data = m_tcp->data = this;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ size_t xmrig::HttpContext::parse(const char *data, size_t size)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return http_parser_execute(m_parser, &http_settings, data, size);
|
return llhttp_execute(m_parser, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ void xmrig::HttpContext::closeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int xmrig::HttpContext::onHeaderField(http_parser *parser, const char *at, size_t length)
|
int xmrig::HttpContext::onHeaderField(llhttp_t *parser, const char *at, size_t length)
|
||||||
{
|
{
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ int xmrig::HttpContext::onHeaderField(http_parser *parser, const char *at, size_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int xmrig::HttpContext::onHeaderValue(http_parser *parser, const char *at, size_t length)
|
int xmrig::HttpContext::onHeaderValue(llhttp_t *parser, const char *at, size_t length)
|
||||||
{
|
{
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
|
|
||||||
|
@ -225,14 +225,14 @@ int xmrig::HttpContext::onHeaderValue(http_parser *parser, const char *at, size_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::HttpContext::attach(http_parser_settings *settings)
|
void xmrig::HttpContext::attach(llhttp_settings_t *settings)
|
||||||
{
|
{
|
||||||
settings->on_message_begin = nullptr;
|
settings->on_message_begin = nullptr;
|
||||||
settings->on_status = nullptr;
|
settings->on_status = nullptr;
|
||||||
settings->on_chunk_header = nullptr;
|
settings->on_chunk_header = nullptr;
|
||||||
settings->on_chunk_complete = nullptr;
|
settings->on_chunk_complete = nullptr;
|
||||||
|
|
||||||
settings->on_url = [](http_parser *parser, const char *at, size_t length) -> int
|
settings->on_url = [](llhttp_t *parser, const char *at, size_t length) -> int
|
||||||
{
|
{
|
||||||
static_cast<HttpContext*>(parser->data)->url = std::string(at, length);
|
static_cast<HttpContext*>(parser->data)->url = std::string(at, length);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -241,7 +241,7 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
|
||||||
settings->on_header_field = onHeaderField;
|
settings->on_header_field = onHeaderField;
|
||||||
settings->on_header_value = onHeaderValue;
|
settings->on_header_value = onHeaderValue;
|
||||||
|
|
||||||
settings->on_headers_complete = [](http_parser* parser) -> int {
|
settings->on_headers_complete = [](llhttp_t *parser) -> int {
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
ctx->status = parser->status_code;
|
ctx->status = parser->status_code;
|
||||||
|
|
||||||
|
@ -256,14 +256,14 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings->on_body = [](http_parser *parser, const char *at, size_t len) -> int
|
settings->on_body = [](llhttp_t *parser, const char *at, size_t len) -> int
|
||||||
{
|
{
|
||||||
static_cast<HttpContext*>(parser->data)->body.append(at, len);
|
static_cast<HttpContext*>(parser->data)->body.append(at, len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings->on_message_complete = [](http_parser *parser) -> int
|
settings->on_message_complete = [](llhttp_t *parser) -> int
|
||||||
{
|
{
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
auto listener = ctx->httpListener();
|
auto listener = ctx->httpListener();
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
#define XMRIG_HTTPCONTEXT_H
|
#define XMRIG_HTTPCONTEXT_H
|
||||||
|
|
||||||
|
|
||||||
using http_parser = struct http_parser;
|
using llhttp_settings_t = struct llhttp_settings_s;
|
||||||
using http_parser_settings = struct http_parser_settings;
|
using llhttp_t = struct llhttp__internal_s;
|
||||||
using uv_connect_t = struct uv_connect_s;
|
using uv_connect_t = struct uv_connect_s;
|
||||||
using uv_handle_t = struct uv_handle_s;
|
using uv_handle_t = struct uv_handle_s;
|
||||||
using uv_stream_t = struct uv_stream_s;
|
using uv_stream_t = struct uv_stream_s;
|
||||||
|
@ -76,15 +76,15 @@ protected:
|
||||||
private:
|
private:
|
||||||
inline IHttpListener *httpListener() const { return m_listener.expired() ? nullptr : m_listener.lock().get(); }
|
inline IHttpListener *httpListener() const { return m_listener.expired() ? nullptr : m_listener.lock().get(); }
|
||||||
|
|
||||||
static int onHeaderField(http_parser *parser, const char *at, size_t length);
|
static int onHeaderField(llhttp_t *parser, const char *at, size_t length);
|
||||||
static int onHeaderValue(http_parser *parser, const char *at, size_t length);
|
static int onHeaderValue(llhttp_t *parser, const char *at, size_t length);
|
||||||
static void attach(http_parser_settings *settings);
|
static void attach(llhttp_settings_t *settings);
|
||||||
|
|
||||||
void setHeader();
|
void setHeader();
|
||||||
|
|
||||||
bool m_wasHeaderValue = false;
|
bool m_wasHeaderValue = false;
|
||||||
const uint64_t m_timestamp;
|
const uint64_t m_timestamp;
|
||||||
http_parser *m_parser;
|
llhttp_t *m_parser;
|
||||||
std::string m_lastHeaderField;
|
std::string m_lastHeaderField;
|
||||||
std::string m_lastHeaderValue;
|
std::string m_lastHeaderValue;
|
||||||
std::weak_ptr<IHttpListener> m_listener;
|
std::weak_ptr<IHttpListener> m_listener;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
@ -29,6 +29,76 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
|
/* Status Codes */
|
||||||
|
#define HTTP_STATUS_MAP(XX) \
|
||||||
|
XX(100, CONTINUE, Continue) \
|
||||||
|
XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
|
||||||
|
XX(102, PROCESSING, Processing) \
|
||||||
|
XX(200, OK, OK) \
|
||||||
|
XX(201, CREATED, Created) \
|
||||||
|
XX(202, ACCEPTED, Accepted) \
|
||||||
|
XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
|
||||||
|
XX(204, NO_CONTENT, No Content) \
|
||||||
|
XX(205, RESET_CONTENT, Reset Content) \
|
||||||
|
XX(206, PARTIAL_CONTENT, Partial Content) \
|
||||||
|
XX(207, MULTI_STATUS, Multi-Status) \
|
||||||
|
XX(208, ALREADY_REPORTED, Already Reported) \
|
||||||
|
XX(226, IM_USED, IM Used) \
|
||||||
|
XX(300, MULTIPLE_CHOICES, Multiple Choices) \
|
||||||
|
XX(301, MOVED_PERMANENTLY, Moved Permanently) \
|
||||||
|
XX(302, FOUND, Found) \
|
||||||
|
XX(303, SEE_OTHER, See Other) \
|
||||||
|
XX(304, NOT_MODIFIED, Not Modified) \
|
||||||
|
XX(305, USE_PROXY, Use Proxy) \
|
||||||
|
XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
|
||||||
|
XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
|
||||||
|
XX(400, BAD_REQUEST, Bad Request) \
|
||||||
|
XX(401, UNAUTHORIZED, Unauthorized) \
|
||||||
|
XX(402, PAYMENT_REQUIRED, Payment Required) \
|
||||||
|
XX(403, FORBIDDEN, Forbidden) \
|
||||||
|
XX(404, NOT_FOUND, Not Found) \
|
||||||
|
XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
|
||||||
|
XX(406, NOT_ACCEPTABLE, Not Acceptable) \
|
||||||
|
XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
|
||||||
|
XX(408, REQUEST_TIMEOUT, Request Timeout) \
|
||||||
|
XX(409, CONFLICT, Conflict) \
|
||||||
|
XX(410, GONE, Gone) \
|
||||||
|
XX(411, LENGTH_REQUIRED, Length Required) \
|
||||||
|
XX(412, PRECONDITION_FAILED, Precondition Failed) \
|
||||||
|
XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
|
||||||
|
XX(414, URI_TOO_LONG, URI Too Long) \
|
||||||
|
XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
|
||||||
|
XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
|
||||||
|
XX(417, EXPECTATION_FAILED, Expectation Failed) \
|
||||||
|
XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
|
||||||
|
XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
|
||||||
|
XX(423, LOCKED, Locked) \
|
||||||
|
XX(424, FAILED_DEPENDENCY, Failed Dependency) \
|
||||||
|
XX(426, UPGRADE_REQUIRED, Upgrade Required) \
|
||||||
|
XX(428, PRECONDITION_REQUIRED, Precondition Required) \
|
||||||
|
XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
|
||||||
|
XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
|
||||||
|
XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
|
||||||
|
XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
|
||||||
|
XX(501, NOT_IMPLEMENTED, Not Implemented) \
|
||||||
|
XX(502, BAD_GATEWAY, Bad Gateway) \
|
||||||
|
XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
|
||||||
|
XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
|
||||||
|
XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
|
||||||
|
XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
|
||||||
|
XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
|
||||||
|
XX(508, LOOP_DETECTED, Loop Detected) \
|
||||||
|
XX(510, NOT_EXTENDED, Not Extended) \
|
||||||
|
XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
|
||||||
|
|
||||||
|
enum http_status
|
||||||
|
{
|
||||||
|
# define XX(num, name, string) HTTP_STATUS_##name = num,
|
||||||
|
HTTP_STATUS_MAP(XX)
|
||||||
|
# undef XX
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +108,17 @@ const std::string HttpData::kContentTypeL = "content-type";
|
||||||
const std::string HttpData::kTextPlain = "text/plain";
|
const std::string HttpData::kTextPlain = "text/plain";
|
||||||
|
|
||||||
|
|
||||||
|
static const char *http_status_str(enum http_status s)
|
||||||
|
{
|
||||||
|
switch (s) {
|
||||||
|
# define XX(num, name, string) case HTTP_STATUS_##name: return #string;
|
||||||
|
HTTP_STATUS_MAP(XX)
|
||||||
|
# undef XX
|
||||||
|
default: return "<unknown>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,17 +136,7 @@ bool xmrig::HttpData::isJSON() const
|
||||||
|
|
||||||
const char *xmrig::HttpData::methodName() const
|
const char *xmrig::HttpData::methodName() const
|
||||||
{
|
{
|
||||||
return http_method_str(static_cast<http_method>(method));
|
return llhttp_method_name(static_cast<llhttp_method>(method));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char *xmrig::HttpData::statusName() const
|
|
||||||
{
|
|
||||||
if (status < 0) {
|
|
||||||
return uv_strerror(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
return http_status_str(static_cast<http_status>(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,3 +165,13 @@ rapidjson::Document xmrig::HttpData::json() const
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::HttpData::statusName(int status)
|
||||||
|
{
|
||||||
|
if (status < 0) {
|
||||||
|
return uv_strerror(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return http_status_str(static_cast<http_status>(status));
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -47,6 +47,7 @@ public:
|
||||||
inline HttpData(uint64_t id) : m_id(id) {}
|
inline HttpData(uint64_t id) : m_id(id) {}
|
||||||
virtual ~HttpData() = default;
|
virtual ~HttpData() = default;
|
||||||
|
|
||||||
|
inline const char *statusName() const { return statusName(status); }
|
||||||
inline uint64_t id() const { return m_id; }
|
inline uint64_t id() const { return m_id; }
|
||||||
|
|
||||||
virtual bool isRequest() const = 0;
|
virtual bool isRequest() const = 0;
|
||||||
|
@ -59,9 +60,10 @@ public:
|
||||||
|
|
||||||
bool isJSON() const;
|
bool isJSON() const;
|
||||||
const char *methodName() const;
|
const char *methodName() const;
|
||||||
const char *statusName() const;
|
|
||||||
rapidjson::Document json() const;
|
rapidjson::Document json() const;
|
||||||
|
|
||||||
|
static const char *statusName(int status);
|
||||||
|
|
||||||
int method = 0;
|
int method = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int userType = 0;
|
int userType = 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpListener.h"
|
#include "base/net/http/HttpListener.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ void xmrig::HttpListener::onHttpData(const HttpData &data)
|
||||||
# ifdef APP_DEBUG
|
# ifdef APP_DEBUG
|
||||||
if (!data.isRequest()) {
|
if (!data.isRequest()) {
|
||||||
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||||
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
|
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), llhttp_method_name(static_cast<llhttp_method>(data.method)), data.url.data(),
|
||||||
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
|
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
|
||||||
|
|
||||||
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
|
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpResponse.h"
|
#include "base/net/http/HttpResponse.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/http/HttpContext.h"
|
#include "base/net/http/HttpContext.h"
|
||||||
|
|
||||||
|
@ -78,7 +72,7 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
||||||
setHeader("Connection", "close");
|
setHeader("Connection", "close");
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "HTTP/1.1 " << statusCode() << " " << http_status_str(static_cast<http_status>(statusCode())) << kCRLF;
|
ss << "HTTP/1.1 " << statusCode() << " " << HttpData::statusName(statusCode()) << kCRLF;
|
||||||
|
|
||||||
for (auto &header : m_headers) {
|
for (auto &header : m_headers) {
|
||||||
ss << header.first << ": " << header.second << kCRLF;
|
ss << header.first << ": " << header.second << kCRLF;
|
||||||
|
@ -97,7 +91,7 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
||||||
|
|
||||||
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""),
|
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""),
|
||||||
ctx->ip().c_str(),
|
ctx->ip().c_str(),
|
||||||
http_method_str(static_cast<http_method>(ctx->method)),
|
llhttp_method_name(static_cast<llhttp_method>(ctx->method)),
|
||||||
ctx->url.c_str(),
|
ctx->url.c_str(),
|
||||||
err ? 31 : 32,
|
err ? 31 : 32,
|
||||||
statusCode(),
|
statusCode(),
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,7 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_HTTPRESPONSE_H
|
#ifndef XMRIG_HTTPRESPONSE_H
|
||||||
#define XMRIG_HTTPRESPONSE_H
|
#define XMRIG_HTTPRESPONSE_H
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/https/HttpsContext.h"
|
#include "base/net/https/HttpsContext.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/net/tls/TlsContext.h"
|
#include "base/net/tls/TlsContext.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/stratum/DaemonClient.h"
|
#include "base/net/stratum/DaemonClient.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
@ -151,7 +150,7 @@ void xmrig::DaemonClient::connect(const Pool &pool)
|
||||||
|
|
||||||
void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
||||||
{
|
{
|
||||||
if (data.status != HTTP_STATUS_OK) {
|
if (data.status != 200) {
|
||||||
return retry();
|
return retry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/stratum/SelfSelectClient.h"
|
#include "base/net/stratum/SelfSelectClient.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
@ -288,7 +287,7 @@ void xmrig::SelfSelectClient::submitOriginDaemon(const JobResult& result)
|
||||||
|
|
||||||
void xmrig::SelfSelectClient::onHttpData(const HttpData &data)
|
void xmrig::SelfSelectClient::onHttpData(const HttpData &data)
|
||||||
{
|
{
|
||||||
if (data.status != HTTP_STATUS_OK) {
|
if (data.status != 200) {
|
||||||
return retry();
|
return retry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue