midori_http_parser 0.6.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.gitmodules +6 -0
- data/.travis.yml +33 -0
- data/Gemfile +2 -0
- data/LICENSE-MIT +20 -0
- data/README.md +90 -0
- data/Rakefile +6 -0
- data/bench/standalone.rb +23 -0
- data/bench/thin.rb +58 -0
- data/ext/ruby_http_parser/.gitignore +1 -0
- data/ext/ruby_http_parser/RubyHttpParserService.java +18 -0
- data/ext/ruby_http_parser/ext_help.h +18 -0
- data/ext/ruby_http_parser/extconf.rb +24 -0
- data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +495 -0
- data/ext/ruby_http_parser/ruby_http_parser.c +516 -0
- data/ext/ruby_http_parser/vendor/.gitkeep +0 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/AUTHORS +32 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT +48 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/README.md +183 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/TODO +28 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +74 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +2175 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.gyp +79 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +304 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/Http-parser.java.iml +22 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/FieldData.java +41 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +8 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +34 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +12 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +9 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +113 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +36 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParserUrl.java +76 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +256 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserType.java +13 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/Util.java +111 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPCallback.java +5 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPDataCallback.java +25 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPErrorCallback.java +7 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +2171 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +83 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +374 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/ParseUrl.java +51 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +69 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +52 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +16 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +48 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +212 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +62 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +117 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +27 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Url.java +127 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +236 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +59 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/test.c +3425 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +845 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +17 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/byte_constants.rb +6 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/const_char.rb +13 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/lowcase.rb +15 -0
- data/ext/ruby_http_parser/vendor/http-parser-java/tools/parse_tests.rb +33 -0
- data/ext/ruby_http_parser/vendor/http-parser/AUTHORS +68 -0
- data/ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT +23 -0
- data/ext/ruby_http_parser/vendor/http-parser/README.md +246 -0
- data/ext/ruby_http_parser/vendor/http-parser/bench.c +111 -0
- data/ext/ruby_http_parser/vendor/http-parser/contrib/parsertrace.c +160 -0
- data/ext/ruby_http_parser/vendor/http-parser/contrib/url_parser.c +47 -0
- data/ext/ruby_http_parser/vendor/http-parser/http_parser.c +2470 -0
- data/ext/ruby_http_parser/vendor/http-parser/http_parser.gyp +111 -0
- data/ext/ruby_http_parser/vendor/http-parser/http_parser.h +432 -0
- data/ext/ruby_http_parser/vendor/http-parser/test.c +4226 -0
- data/ext/ruby_http_parser/vendor/http-parser/test_fast +0 -0
- data/ext/ruby_http_parser/vendor/http-parser/test_g +0 -0
- data/lib/http/parser.rb +1 -0
- data/lib/http_parser.rb +21 -0
- data/midori_http_parser.gemspec +24 -0
- data/spec/parser_spec.rb +376 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/requests.json +631 -0
- data/spec/support/responses.json +375 -0
- data/tasks/compile.rake +42 -0
- data/tasks/fixtures.rake +71 -0
- data/tasks/spec.rake +5 -0
- data/tasks/submodules.rake +7 -0
- metadata +206 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
# This file is used with the GYP meta build system.
|
2
|
+
# http://code.google.com/p/gyp/
|
3
|
+
# To build try this:
|
4
|
+
# svn co http://gyp.googlecode.com/svn/trunk gyp
|
5
|
+
# ./gyp/gyp -f make --depth=`pwd` http_parser.gyp
|
6
|
+
# ./out/Debug/test
|
7
|
+
{
|
8
|
+
'target_defaults': {
|
9
|
+
'default_configuration': 'Debug',
|
10
|
+
'configurations': {
|
11
|
+
# TODO: hoist these out and put them somewhere common, because
|
12
|
+
# RuntimeLibrary MUST MATCH across the entire project
|
13
|
+
'Debug': {
|
14
|
+
'defines': [ 'DEBUG', '_DEBUG' ],
|
15
|
+
'msvs_settings': {
|
16
|
+
'VCCLCompilerTool': {
|
17
|
+
'RuntimeLibrary': 1, # static debug
|
18
|
+
},
|
19
|
+
},
|
20
|
+
},
|
21
|
+
'Release': {
|
22
|
+
'defines': [ 'NDEBUG' ],
|
23
|
+
'msvs_settings': {
|
24
|
+
'VCCLCompilerTool': {
|
25
|
+
'RuntimeLibrary': 0, # static release
|
26
|
+
},
|
27
|
+
},
|
28
|
+
}
|
29
|
+
},
|
30
|
+
'msvs_settings': {
|
31
|
+
'VCCLCompilerTool': {
|
32
|
+
},
|
33
|
+
'VCLibrarianTool': {
|
34
|
+
},
|
35
|
+
'VCLinkerTool': {
|
36
|
+
'GenerateDebugInformation': 'true',
|
37
|
+
},
|
38
|
+
},
|
39
|
+
'conditions': [
|
40
|
+
['OS == "win"', {
|
41
|
+
'defines': [
|
42
|
+
'WIN32'
|
43
|
+
],
|
44
|
+
}]
|
45
|
+
],
|
46
|
+
},
|
47
|
+
|
48
|
+
'targets': [
|
49
|
+
{
|
50
|
+
'target_name': 'http_parser',
|
51
|
+
'type': 'static_library',
|
52
|
+
'include_dirs': [ '.' ],
|
53
|
+
'direct_dependent_settings': {
|
54
|
+
'include_dirs': [ '.' ],
|
55
|
+
},
|
56
|
+
'defines': [ 'HTTP_PARSER_STRICT=0' ],
|
57
|
+
'sources': [ './http_parser.c', ],
|
58
|
+
'conditions': [
|
59
|
+
['OS=="win"', {
|
60
|
+
'msvs_settings': {
|
61
|
+
'VCCLCompilerTool': {
|
62
|
+
# Compile as C++. http_parser.c is actually C99, but C++ is
|
63
|
+
# close enough in this case.
|
64
|
+
'CompileAs': 2,
|
65
|
+
},
|
66
|
+
},
|
67
|
+
}]
|
68
|
+
],
|
69
|
+
},
|
70
|
+
|
71
|
+
{
|
72
|
+
'target_name': 'test',
|
73
|
+
'type': 'executable',
|
74
|
+
'dependencies': [ 'http_parser' ],
|
75
|
+
'sources': [ 'test.c' ]
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
|
@@ -0,0 +1,304 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
#ifndef http_parser_h
|
22
|
+
#define http_parser_h
|
23
|
+
#ifdef __cplusplus
|
24
|
+
extern "C" {
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#define HTTP_PARSER_VERSION_MAJOR 2
|
28
|
+
#define HTTP_PARSER_VERSION_MINOR 0
|
29
|
+
|
30
|
+
#include <sys/types.h>
|
31
|
+
#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
|
32
|
+
#include <BaseTsd.h>
|
33
|
+
#include <stddef.h>
|
34
|
+
typedef __int8 int8_t;
|
35
|
+
typedef unsigned __int8 uint8_t;
|
36
|
+
typedef __int16 int16_t;
|
37
|
+
typedef unsigned __int16 uint16_t;
|
38
|
+
typedef __int32 int32_t;
|
39
|
+
typedef unsigned __int32 uint32_t;
|
40
|
+
typedef __int64 int64_t;
|
41
|
+
typedef unsigned __int64 uint64_t;
|
42
|
+
#else
|
43
|
+
#include <stdint.h>
|
44
|
+
#endif
|
45
|
+
|
46
|
+
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
47
|
+
* faster
|
48
|
+
*/
|
49
|
+
#ifndef HTTP_PARSER_STRICT
|
50
|
+
# define HTTP_PARSER_STRICT 1
|
51
|
+
#endif
|
52
|
+
|
53
|
+
/* Maximium header size allowed */
|
54
|
+
#define HTTP_MAX_HEADER_SIZE (80*1024)
|
55
|
+
|
56
|
+
|
57
|
+
typedef struct http_parser http_parser;
|
58
|
+
typedef struct http_parser_settings http_parser_settings;
|
59
|
+
|
60
|
+
|
61
|
+
/* Callbacks should return non-zero to indicate an error. The parser will
|
62
|
+
* then halt execution.
|
63
|
+
*
|
64
|
+
* The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
65
|
+
* returning '1' from on_headers_complete will tell the parser that it
|
66
|
+
* should not expect a body. This is used when receiving a response to a
|
67
|
+
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
68
|
+
* chunked' headers that indicate the presence of a body.
|
69
|
+
*
|
70
|
+
* http_data_cb does not return data chunks. It will be call arbitrarally
|
71
|
+
* many times for each string. E.G. you might get 10 callbacks for "on_url"
|
72
|
+
* each providing just a few characters more data.
|
73
|
+
*/
|
74
|
+
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
|
75
|
+
typedef int (*http_cb) (http_parser*);
|
76
|
+
|
77
|
+
|
78
|
+
/* Request Methods */
|
79
|
+
#define HTTP_METHOD_MAP(XX) \
|
80
|
+
XX(0, DELETE, DELETE) \
|
81
|
+
XX(1, GET, GET) \
|
82
|
+
XX(2, HEAD, HEAD) \
|
83
|
+
XX(3, POST, POST) \
|
84
|
+
XX(4, PUT, PUT) \
|
85
|
+
/* pathological */ \
|
86
|
+
XX(5, CONNECT, CONNECT) \
|
87
|
+
XX(6, OPTIONS, OPTIONS) \
|
88
|
+
XX(7, TRACE, TRACE) \
|
89
|
+
/* webdav */ \
|
90
|
+
XX(8, COPY, COPY) \
|
91
|
+
XX(9, LOCK, LOCK) \
|
92
|
+
XX(10, MKCOL, MKCOL) \
|
93
|
+
XX(11, MOVE, MOVE) \
|
94
|
+
XX(12, PROPFIND, PROPFIND) \
|
95
|
+
XX(13, PROPPATCH, PROPPATCH) \
|
96
|
+
XX(14, SEARCH, SEARCH) \
|
97
|
+
XX(15, UNLOCK, UNLOCK) \
|
98
|
+
/* subversion */ \
|
99
|
+
XX(16, REPORT, REPORT) \
|
100
|
+
XX(17, MKACTIVITY, MKACTIVITY) \
|
101
|
+
XX(18, CHECKOUT, CHECKOUT) \
|
102
|
+
XX(19, MERGE, MERGE) \
|
103
|
+
/* upnp */ \
|
104
|
+
XX(20, MSEARCH, M-SEARCH) \
|
105
|
+
XX(21, NOTIFY, NOTIFY) \
|
106
|
+
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
107
|
+
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
108
|
+
/* RFC-5789 */ \
|
109
|
+
XX(24, PATCH, PATCH) \
|
110
|
+
XX(25, PURGE, PURGE) \
|
111
|
+
|
112
|
+
enum http_method
|
113
|
+
{
|
114
|
+
#define XX(num, name, string) HTTP_##name = num,
|
115
|
+
HTTP_METHOD_MAP(XX)
|
116
|
+
#undef XX
|
117
|
+
};
|
118
|
+
|
119
|
+
|
120
|
+
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
|
121
|
+
|
122
|
+
|
123
|
+
/* Flag values for http_parser.flags field */
|
124
|
+
enum flags
|
125
|
+
{ F_CHUNKED = 1 << 0
|
126
|
+
, F_CONNECTION_KEEP_ALIVE = 1 << 1
|
127
|
+
, F_CONNECTION_CLOSE = 1 << 2
|
128
|
+
, F_TRAILING = 1 << 3
|
129
|
+
, F_UPGRADE = 1 << 4
|
130
|
+
, F_SKIPBODY = 1 << 5
|
131
|
+
};
|
132
|
+
|
133
|
+
|
134
|
+
/* Map for errno-related constants
|
135
|
+
*
|
136
|
+
* The provided argument should be a macro that takes 2 arguments.
|
137
|
+
*/
|
138
|
+
#define HTTP_ERRNO_MAP(XX) \
|
139
|
+
/* No error */ \
|
140
|
+
XX(OK, "success") \
|
141
|
+
\
|
142
|
+
/* Callback-related errors */ \
|
143
|
+
XX(CB_message_begin, "the on_message_begin callback failed") \
|
144
|
+
XX(CB_status_complete, "the on_status_complete callback failed") \
|
145
|
+
XX(CB_url, "the on_url callback failed") \
|
146
|
+
XX(CB_header_field, "the on_header_field callback failed") \
|
147
|
+
XX(CB_header_value, "the on_header_value callback failed") \
|
148
|
+
XX(CB_headers_complete, "the on_headers_complete callback failed") \
|
149
|
+
XX(CB_body, "the on_body callback failed") \
|
150
|
+
XX(CB_message_complete, "the on_message_complete callback failed") \
|
151
|
+
\
|
152
|
+
/* Parsing-related errors */ \
|
153
|
+
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
|
154
|
+
XX(HEADER_OVERFLOW, \
|
155
|
+
"too many header bytes seen; overflow detected") \
|
156
|
+
XX(CLOSED_CONNECTION, \
|
157
|
+
"data received after completed connection: close message") \
|
158
|
+
XX(INVALID_VERSION, "invalid HTTP version") \
|
159
|
+
XX(INVALID_STATUS, "invalid HTTP status code") \
|
160
|
+
XX(INVALID_METHOD, "invalid HTTP method") \
|
161
|
+
XX(INVALID_URL, "invalid URL") \
|
162
|
+
XX(INVALID_HOST, "invalid host") \
|
163
|
+
XX(INVALID_PORT, "invalid port") \
|
164
|
+
XX(INVALID_PATH, "invalid path") \
|
165
|
+
XX(INVALID_QUERY_STRING, "invalid query string") \
|
166
|
+
XX(INVALID_FRAGMENT, "invalid fragment") \
|
167
|
+
XX(LF_EXPECTED, "LF character expected") \
|
168
|
+
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
|
169
|
+
XX(INVALID_CONTENT_LENGTH, \
|
170
|
+
"invalid character in content-length header") \
|
171
|
+
XX(INVALID_CHUNK_SIZE, \
|
172
|
+
"invalid character in chunk size header") \
|
173
|
+
XX(INVALID_CONSTANT, "invalid constant string") \
|
174
|
+
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
|
175
|
+
XX(STRICT, "strict mode assertion failed") \
|
176
|
+
XX(PAUSED, "parser is paused") \
|
177
|
+
XX(UNKNOWN, "an unknown error occurred")
|
178
|
+
|
179
|
+
|
180
|
+
/* Define HPE_* values for each errno value above */
|
181
|
+
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
|
182
|
+
enum http_errno {
|
183
|
+
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
184
|
+
};
|
185
|
+
#undef HTTP_ERRNO_GEN
|
186
|
+
|
187
|
+
|
188
|
+
/* Get an http_errno value from an http_parser */
|
189
|
+
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
|
190
|
+
|
191
|
+
|
192
|
+
struct http_parser {
|
193
|
+
/** PRIVATE **/
|
194
|
+
unsigned char type : 2; /* enum http_parser_type */
|
195
|
+
unsigned char flags : 6; /* F_* values from 'flags' enum; semi-public */
|
196
|
+
unsigned char state; /* enum state from http_parser.c */
|
197
|
+
unsigned char header_state; /* enum header_state from http_parser.c */
|
198
|
+
unsigned char index; /* index into current matcher */
|
199
|
+
|
200
|
+
uint32_t nread; /* # bytes read in various scenarios */
|
201
|
+
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
|
202
|
+
|
203
|
+
/** READ-ONLY **/
|
204
|
+
unsigned short http_major;
|
205
|
+
unsigned short http_minor;
|
206
|
+
unsigned short status_code; /* responses only */
|
207
|
+
unsigned char method; /* requests only */
|
208
|
+
unsigned char http_errno : 7;
|
209
|
+
|
210
|
+
/* 1 = Upgrade header was present and the parser has exited because of that.
|
211
|
+
* 0 = No upgrade header present.
|
212
|
+
* Should be checked when http_parser_execute() returns in addition to
|
213
|
+
* error checking.
|
214
|
+
*/
|
215
|
+
unsigned char upgrade : 1;
|
216
|
+
|
217
|
+
/** PUBLIC **/
|
218
|
+
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
219
|
+
};
|
220
|
+
|
221
|
+
|
222
|
+
struct http_parser_settings {
|
223
|
+
http_cb on_message_begin;
|
224
|
+
http_data_cb on_url;
|
225
|
+
http_cb on_status_complete;
|
226
|
+
http_data_cb on_header_field;
|
227
|
+
http_data_cb on_header_value;
|
228
|
+
http_cb on_headers_complete;
|
229
|
+
http_data_cb on_body;
|
230
|
+
http_cb on_message_complete;
|
231
|
+
};
|
232
|
+
|
233
|
+
|
234
|
+
enum http_parser_url_fields
|
235
|
+
{ UF_SCHEMA = 0
|
236
|
+
, UF_HOST = 1
|
237
|
+
, UF_PORT = 2
|
238
|
+
, UF_PATH = 3
|
239
|
+
, UF_QUERY = 4
|
240
|
+
, UF_FRAGMENT = 5
|
241
|
+
, UF_USERINFO = 6
|
242
|
+
, UF_MAX = 7
|
243
|
+
};
|
244
|
+
|
245
|
+
|
246
|
+
/* Result structure for http_parser_parse_url().
|
247
|
+
*
|
248
|
+
* Callers should index into field_data[] with UF_* values iff field_set
|
249
|
+
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
250
|
+
* because we probably have padding left over), we convert any port to
|
251
|
+
* a uint16_t.
|
252
|
+
*/
|
253
|
+
struct http_parser_url {
|
254
|
+
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
|
255
|
+
uint16_t port; /* Converted UF_PORT string */
|
256
|
+
|
257
|
+
struct {
|
258
|
+
uint16_t off; /* Offset into buffer in which field starts */
|
259
|
+
uint16_t len; /* Length of run in buffer */
|
260
|
+
} field_data[UF_MAX];
|
261
|
+
};
|
262
|
+
|
263
|
+
|
264
|
+
void http_parser_init(http_parser *parser, enum http_parser_type type);
|
265
|
+
|
266
|
+
|
267
|
+
size_t http_parser_execute(http_parser *parser,
|
268
|
+
const http_parser_settings *settings,
|
269
|
+
const char *data,
|
270
|
+
size_t len);
|
271
|
+
|
272
|
+
|
273
|
+
/* If http_should_keep_alive() in the on_headers_complete or
|
274
|
+
* on_message_complete callback returns 0, then this should be
|
275
|
+
* the last message on the connection.
|
276
|
+
* If you are the server, respond with the "Connection: close" header.
|
277
|
+
* If you are the client, close the connection.
|
278
|
+
*/
|
279
|
+
int http_should_keep_alive(const http_parser *parser);
|
280
|
+
|
281
|
+
/* Returns a string version of the HTTP method. */
|
282
|
+
const char *http_method_str(enum http_method m);
|
283
|
+
|
284
|
+
/* Return a string name of the given error */
|
285
|
+
const char *http_errno_name(enum http_errno err);
|
286
|
+
|
287
|
+
/* Return a string description of the given error */
|
288
|
+
const char *http_errno_description(enum http_errno err);
|
289
|
+
|
290
|
+
/* Parse a URL; return nonzero on failure */
|
291
|
+
int http_parser_parse_url(const char *buf, size_t buflen,
|
292
|
+
int is_connect,
|
293
|
+
struct http_parser_url *u);
|
294
|
+
|
295
|
+
/* Pause or un-pause the parser; a nonzero value pauses */
|
296
|
+
void http_parser_pause(http_parser *parser, int paused);
|
297
|
+
|
298
|
+
/* Checks if this is the final chunk of the body. */
|
299
|
+
int http_body_is_final(const http_parser *parser);
|
300
|
+
|
301
|
+
#ifdef __cplusplus
|
302
|
+
}
|
303
|
+
#endif
|
304
|
+
#endif
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$">
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$/impl" isTestSource="false" />
|
7
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
8
|
+
</content>
|
9
|
+
<orderEntry type="inheritedJdk" />
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
11
|
+
<orderEntry type="module-library">
|
12
|
+
<library>
|
13
|
+
<CLASSES>
|
14
|
+
<root url="jar://$MODULE_DIR$/../ext/primitives.jar!/" />
|
15
|
+
</CLASSES>
|
16
|
+
<JAVADOC />
|
17
|
+
<SOURCES />
|
18
|
+
</library>
|
19
|
+
</orderEntry>
|
20
|
+
</component>
|
21
|
+
</module>
|
22
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
package http_parser;
|
2
|
+
|
3
|
+
public class FieldData {
|
4
|
+
public int off;
|
5
|
+
public int len;
|
6
|
+
|
7
|
+
public FieldData(){}
|
8
|
+
|
9
|
+
public FieldData(int off, int len){
|
10
|
+
this.off = off;
|
11
|
+
this.len = len;
|
12
|
+
}
|
13
|
+
|
14
|
+
@Override
|
15
|
+
public boolean equals(Object o) {
|
16
|
+
if (this == o) return true;
|
17
|
+
if (o == null || getClass() != o.getClass()) return false;
|
18
|
+
|
19
|
+
FieldData fieldData = (FieldData) o;
|
20
|
+
|
21
|
+
if (len != fieldData.len) return false;
|
22
|
+
if (off != fieldData.off) return false;
|
23
|
+
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
|
27
|
+
@Override
|
28
|
+
public int hashCode() {
|
29
|
+
int result = off;
|
30
|
+
result = 31 * result + len;
|
31
|
+
return result;
|
32
|
+
}
|
33
|
+
|
34
|
+
@Override
|
35
|
+
public String toString() {
|
36
|
+
return "FieldData{" +
|
37
|
+
"off=" + off +
|
38
|
+
", len=" + len +
|
39
|
+
'}';
|
40
|
+
}
|
41
|
+
}
|