Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
eb21e6f8
Commit
eb21e6f8
authored
Jan 17, 2019
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'update-http-parser'
parents
439dbce6
ab2aa567
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
724 additions
and
321 deletions
+724
-321
src/http2.cc
src/http2.cc
+4
-0
src/http2_test.cc
src/http2_test.cc
+2
-6
third-party/http-parser/CONTRIBUTIONS
third-party/http-parser/CONTRIBUTIONS
+0
-4
third-party/http-parser/LICENSE-MIT
third-party/http-parser/LICENSE-MIT
+1
-5
third-party/http-parser/README.md
third-party/http-parser/README.md
+5
-5
third-party/http-parser/bench.c
third-party/http-parser/bench.c
+26
-9
third-party/http-parser/contrib/parsertrace.c
third-party/http-parser/contrib/parsertrace.c
+1
-4
third-party/http-parser/http_parser.c
third-party/http-parser/http_parser.c
+194
-163
third-party/http-parser/http_parser.h
third-party/http-parser/http_parser.h
+81
-4
third-party/http-parser/test.c
third-party/http-parser/test.c
+410
-121
No files found.
src/http2.cc
View file @
eb21e6f8
...
...
@@ -1581,6 +1581,10 @@ int construct_push_component(BlockAllocator &balloc, StringRef &scheme,
int
rv
;
StringRef
rel
,
relq
;
if
(
uri
.
size
()
==
0
)
{
return
-
1
;
}
http_parser_url
u
{};
rv
=
http_parser_parse_url
(
uri
.
c_str
(),
uri
.
size
(),
0
,
&
u
);
...
...
src/http2_test.cc
View file @
eb21e6f8
...
...
@@ -995,12 +995,8 @@ void test_http2_construct_push_component(void) {
uri
=
StringRef
{};
CU_ASSERT
(
0
==
http2
::
construct_push_component
(
balloc
,
scheme
,
authority
,
path
,
base
,
uri
));
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
"/"
==
path
);
CU_ASSERT
(
-
1
==
http2
::
construct_push_component
(
balloc
,
scheme
,
authority
,
path
,
base
,
uri
));
scheme
=
StringRef
{};
authority
=
StringRef
{};
path
=
StringRef
{};
...
...
third-party/http-parser/CONTRIBUTIONS
deleted
100644 → 0
View file @
439dbce6
Contributors must agree to the Contributor License Agreement before patches
can be accepted.
http://spreadsheets2.google.com/viewform?hl=en&formkey=dDJXOGUwbzlYaWM4cHN1MERwQS1CSnc6MQ
third-party/http-parser/LICENSE-MIT
View file @
eb21e6f8
http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
Igor Sysoev.
Additional changes are licensed under the same terms as NGINX and
copyright Joyent, Inc. and other Node contributors. All rights reserved.
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
...
...
third-party/http-parser/README.md
View file @
eb21e6f8
...
...
@@ -72,9 +72,9 @@ if (parser->upgrade) {
}
```
HTTP
needs to know where the end of the stream is. For example, sometimes
`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
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.
...
...
@@ -93,7 +93,7 @@ the on_body callback.
The Special Problem of Upgrade
------------------------------
HTTP
supports upgrading the connection to a different protocol. An
`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
...
...
@@ -144,7 +144,7 @@ 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
callback in a threadsafe manner. This allows
`http_parser`
to be used in
multi-threaded contexts.
Example:
...
...
@@ -202,7 +202,7 @@ void http_parser_thread(socket_t sock) {
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
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.
...
...
third-party/http-parser/bench.c
View file @
eb21e6f8
...
...
@@ -20,10 +20,14 @@
*/
#include "http_parser.h"
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
/* 8 gb */
static
const
int64_t
kBytes
=
8LL
<<
30
;
static
const
char
data
[]
=
"POST /joyent/http-parser HTTP/1.1
\r\n
"
"Host: github.com
\r\n
"
...
...
@@ -38,7 +42,7 @@ static const char data[] =
"Referer: https://github.com/joyent/http-parser
\r\n
"
"Connection: keep-alive
\r\n
"
"Transfer-Encoding: chunked
\r\n
"
"Cache-Control: max-age=0
\r\n\r\n
b
\r\n
hello world
\r\n
0
\r\n
\r\n
"
;
"Cache-Control: max-age=0
\r\n\r\n
b
\r\n
hello world
\r\n
0
\r\n
"
;
static
const
size_t
data_len
=
sizeof
(
data
)
-
1
;
static
int
on_info
(
http_parser
*
p
)
{
...
...
@@ -67,13 +71,13 @@ int bench(int iter_count, int silent) {
int
err
;
struct
timeval
start
;
struct
timeval
end
;
float
rps
;
if
(
!
silent
)
{
err
=
gettimeofday
(
&
start
,
NULL
);
assert
(
err
==
0
);
}
fprintf
(
stderr
,
"req_len=%d
\n
"
,
(
int
)
data_len
);
for
(
i
=
0
;
i
<
iter_count
;
i
++
)
{
size_t
parsed
;
http_parser_init
(
&
parser
,
HTTP_REQUEST
);
...
...
@@ -83,17 +87,27 @@ int bench(int iter_count, int silent) {
}
if
(
!
silent
)
{
double
elapsed
;
double
bw
;
double
total
;
err
=
gettimeofday
(
&
end
,
NULL
);
assert
(
err
==
0
);
fprintf
(
stdout
,
"Benchmark result:
\n
"
);
rps
=
(
float
)
(
end
.
tv_sec
-
start
.
tv_sec
)
+
(
end
.
tv_usec
-
start
.
tv_usec
)
*
1e-6
f
;
fprintf
(
stdout
,
"Took %f seconds to run
\n
"
,
rps
);
elapsed
=
(
double
)
(
end
.
tv_sec
-
start
.
tv_sec
)
+
(
end
.
tv_usec
-
start
.
tv_usec
)
*
1e-6
f
;
total
=
(
double
)
iter_count
*
data_len
;
bw
=
(
double
)
total
/
elapsed
;
fprintf
(
stdout
,
"%.2f mb | %.2f mb/s | %.2f req/sec | %.2f s
\n
"
,
(
double
)
total
/
(
1024
*
1024
),
bw
/
(
1024
*
1024
),
(
double
)
iter_count
/
elapsed
,
elapsed
);
rps
=
(
float
)
iter_count
/
rps
;
fprintf
(
stdout
,
"%f req/sec
\n
"
,
rps
);
fflush
(
stdout
);
}
...
...
@@ -101,11 +115,14 @@ int bench(int iter_count, int silent) {
}
int
main
(
int
argc
,
char
**
argv
)
{
int64_t
iterations
;
iterations
=
kBytes
/
(
int64_t
)
data_len
;
if
(
argc
==
2
&&
strcmp
(
argv
[
1
],
"infinite"
)
==
0
)
{
for
(;;)
bench
(
5000000
,
1
);
bench
(
iterations
,
1
);
return
0
;
}
else
{
return
bench
(
5000000
,
0
);
return
bench
(
iterations
,
0
);
}
}
third-party/http-parser/contrib/parsertrace.c
View file @
eb21e6f8
/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev
*
* Additional changes are licensed under the same terms as NGINX and
* copyright Joyent, Inc. and other Node contributors. All rights reserved.
/* 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
...
...
third-party/http-parser/http_parser.c
View file @
eb21e6f8
This diff is collapsed.
Click to expand it.
third-party/http-parser/http_parser.h
View file @
eb21e6f8
...
...
@@ -26,14 +26,13 @@ extern "C" {
/* Also update SONAME in the Makefile whenever you change these. */
#define HTTP_PARSER_VERSION_MAJOR 2
#define HTTP_PARSER_VERSION_MINOR
7
#define HTTP_PARSER_VERSION_PATCH
1
#define HTTP_PARSER_VERSION_MINOR
9
#define HTTP_PARSER_VERSION_PATCH
0
#include <s
ys/types
.h>
#include <s
tddef
.h>
#if defined(_WIN32) && !defined(__MINGW32__) && \
(!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
#include <BaseTsd.h>
#include <stddef.h>
typedef
__int8
int8_t
;
typedef
unsigned
__int8
uint8_t
;
typedef
__int16
int16_t
;
...
...
@@ -90,6 +89,76 @@ 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) \
...
...
@@ -132,6 +201,8 @@ typedef int (*http_cb) (http_parser*);
/* RFC-2068, section 19.6.1.2 */
\
XX(31, LINK, LINK) \
XX(32, UNLINK, UNLINK) \
/* icecast */
\
XX(33, SOURCE, SOURCE) \
enum
http_method
{
...
...
@@ -336,6 +407,9 @@ 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
);
...
...
@@ -356,6 +430,9 @@ 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
...
...
third-party/http-parser/test.c
View file @
eb21e6f8
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment