http_parser.rb 0.5.1-x86-mingw32 → 0.5.2-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/Gemfile.lock +16 -16
  2. data/LICENSE-MIT +20 -0
  3. data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +68 -11
  4. data/ext/ruby_http_parser/ruby_http_parser.c +74 -6
  5. data/ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT +1 -1
  6. data/ext/ruby_http_parser/vendor/http-parser/http_parser.c +52 -10
  7. data/ext/ruby_http_parser/vendor/http-parser/http_parser.h +3 -1
  8. data/ext/ruby_http_parser/vendor/http-parser/test.c +89 -3
  9. data/ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT +26 -1
  10. data/ext/ruby_http_parser/vendor/http-parser-java/README.md +23 -143
  11. data/ext/ruby_http_parser/vendor/http-parser-java/TODO +3 -0
  12. data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +74 -0
  13. data/ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar +0 -0
  14. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +115 -61
  15. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +19 -3
  16. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +8 -0
  17. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +34 -0
  18. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +12 -0
  19. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +4 -2
  20. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +64 -52
  21. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +5 -0
  22. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +323 -0
  23. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/{lolevel/Util.java → Util.java} +27 -28
  24. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +259 -85
  25. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +1 -0
  26. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +324 -0
  27. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +69 -0
  28. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +51 -0
  29. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +15 -0
  30. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +47 -0
  31. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +183 -447
  32. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +61 -0
  33. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +2 -1
  34. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +26 -0
  35. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +165 -0
  36. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +58 -0
  37. data/ext/ruby_http_parser/vendor/http-parser-java/test.c +232 -29
  38. data/ext/ruby_http_parser/vendor/http-parser-java/test_permutations +1 -1
  39. data/ext/ruby_http_parser/vendor/http-parser-java/test_unit +1 -1
  40. data/ext/ruby_http_parser/vendor/http-parser-java/test_utf8 +1 -0
  41. data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +154 -7
  42. data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +17 -0
  43. data/http_parser.rb.gemspec +8 -2
  44. data/lib/1.8/ruby_http_parser.so +0 -0
  45. data/lib/1.9/ruby_http_parser.so +0 -0
  46. data/lib/http_parser.rb +17 -0
  47. data/spec/parser_spec.rb +97 -6
  48. data/tasks/compile.rake +3 -1
  49. metadata +83 -20
  50. data/ext/ruby_http_parser/vendor/http-parser-java/CONTRIBUTIONS +0 -4
@@ -1,20 +1,20 @@
1
1
  HTTP Parser
2
2
  ===========
3
3
 
4
- This is a parser for HTTP messages written in C. It parses both requests and
5
- responses. The parser is designed to be used in performance HTTP
6
- applications. It does not make any syscalls nor allocations, it does not
7
- buffer data, it can be interrupted at anytime. Depending on your
8
- architecture, it only requires about 40 bytes of data per message
9
- stream (in a web server that is per connection).
4
+ This is a parser for HTTP written in Java, based quite heavily on
5
+ the Ryan Dahl's C Version: `http-parser` available here:
6
+
7
+ http://github.com/ry/http-parser
8
+
9
+ It parses both requests and responses. The parser is designed to be used
10
+ in performance HTTP applications.
10
11
 
11
12
  Features:
12
13
 
13
- * No dependencies
14
+ * No dependencies (probably won't be able to keep it up)
14
15
  * Handles persistent streams (keep-alive).
15
16
  * Decodes chunked encoding.
16
17
  * Upgrade support
17
- * Defends against buffer overflow attacks.
18
18
 
19
19
  The parser extracts the following information from HTTP messages:
20
20
 
@@ -27,145 +27,25 @@ The parser extracts the following information from HTTP messages:
27
27
  * Request path, query string, fragment
28
28
  * Message body
29
29
 
30
+ Building
31
+ --------
32
+
33
+ use `ant compile|test|jar`
30
34
 
31
35
  Usage
32
36
  -----
33
37
 
34
- One `http_parser` object is used per TCP connection. Initialize the struct
35
- using `http_parser_init()` and set the callbacks. That might look something
36
- like this for a request parser:
37
-
38
- http_parser_settings settings;
39
- settings.on_path = my_path_callback;
40
- settings.on_header_field = my_header_field_callback;
41
- /* ... */
42
- settings.data = my_socket;
43
-
44
- http_parser *parser = malloc(sizeof(http_parser));
45
- http_parser_init(parser, HTTP_REQUEST);
46
-
47
- When data is received on the socket execute the parser and check for errors.
48
-
49
- size_t len = 80*1024, nparsed;
50
- char buf[len];
51
- ssize_t recved;
52
-
53
- recved = recv(fd, buf, len, 0);
54
-
55
- if (recved < 0) {
56
- /* Handle error. */
57
- }
58
-
59
- /* Start up / continue the parser.
60
- * Note we pass recved==0 to signal that EOF has been recieved.
61
- */
62
- nparsed = http_parser_execute(parser, &settings, buf, recved);
63
-
64
- if (parser->upgrade) {
65
- /* handle new protocol */
66
- } else if (nparsed != recved) {
67
- /* Handle error. Usually just close the connection. */
68
- }
69
-
70
- HTTP needs to know where the end of the stream is. For example, sometimes
71
- servers send responses without Content-Length and expect the client to
72
- consume input (for the body) until EOF. To tell http_parser about EOF, give
73
- `0` as the forth parameter to `http_parser_execute()`. Callbacks and errors
74
- can still be encountered during an EOF, so one must still be prepared
75
- to receive them.
76
-
77
- Scalar valued message information such as `status_code`, `method`, and the
78
- HTTP version are stored in the parser structure. This data is only
79
- temporally stored in `http_parser` and gets reset on each new message. If
80
- this information is needed later, copy it out of the structure during the
81
- `headers_complete` callback.
82
-
83
- The parser decodes the transfer-encoding for both requests and responses
84
- transparently. That is, a chunked encoding is decoded before being sent to
85
- the on_body callback.
86
-
87
-
88
- The Special Problem of Upgrade
89
- ------------------------------
90
-
91
- HTTP supports upgrading the connection to a different protocol. An
92
- increasingly common example of this is the Web Socket protocol which sends
93
- a request like
94
-
95
- GET /demo HTTP/1.1
96
- Upgrade: WebSocket
97
- Connection: Upgrade
98
- Host: example.com
99
- Origin: http://example.com
100
- WebSocket-Protocol: sample
101
-
102
- followed by non-HTTP data.
103
-
104
- (See http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 for more
105
- information the Web Socket protocol.)
106
-
107
- To support this, the parser will treat this as a normal HTTP message without a
108
- body. Issuing both on_headers_complete and on_message_complete callbacks. However
109
- http_parser_execute() will stop parsing at the end of the headers and return.
110
-
111
- The user is expected to check if `parser->upgrade` has been set to 1 after
112
- `http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied
113
- offset by the return value of `http_parser_execute()`.
114
-
115
-
116
- Callbacks
117
- ---------
118
-
119
- During the `http_parser_execute()` call, the callbacks set in
120
- `http_parser_settings` will be executed. The parser maintains state and
121
- never looks behind, so buffering the data is not necessary. If you need to
122
- save certain data for later usage, you can do that from the callbacks.
123
-
124
- There are two types of callbacks:
125
-
126
- * notification `typedef int (*http_cb) (http_parser*);`
127
- Callbacks: on_message_begin, on_headers_complete, on_message_complete.
128
- * data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
129
- Callbacks: (requests only) on_path, on_query_string, on_uri, on_fragment,
130
- (common) on_header_field, on_header_value, on_body;
131
-
132
- Callbacks must return 0 on success. Returning a non-zero value indicates
133
- error to the parser, making it exit immediately.
134
-
135
- In case you parse HTTP message in chunks (i.e. `read()` request line
136
- from socket, parse, read half headers, parse, etc) your data callbacks
137
- may be called more than once. Http-parser guarantees that data pointer is only
138
- valid for the lifetime of callback. You can also `read()` into a heap allocated
139
- buffer to avoid copying memory around if this fits your application.
140
-
141
- Reading headers may be a tricky task if you read/parse headers partially.
142
- Basically, you need to remember whether last header callback was field or value
143
- and apply following logic:
144
-
145
- (on_header_field and on_header_value shortened to on_h_*)
146
- ------------------------ ------------ --------------------------------------------
147
- | State (prev. callback) | Callback | Description/action |
148
- ------------------------ ------------ --------------------------------------------
149
- | nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
150
- | | | into it |
151
- ------------------------ ------------ --------------------------------------------
152
- | value | on_h_field | New header started. |
153
- | | | Copy current name,value buffers to headers |
154
- | | | list and allocate new buffer for new name |
155
- ------------------------ ------------ --------------------------------------------
156
- | field | on_h_field | Previous name continues. Reallocate name |
157
- | | | buffer and append callback data to it |
158
- ------------------------ ------------ --------------------------------------------
159
- | field | on_h_value | Value for current header started. Allocate |
160
- | | | new buffer and copy callback data to it |
161
- ------------------------ ------------ --------------------------------------------
162
- | value | on_h_value | Value continues. Reallocate value buffer |
163
- | | | and append callback data to it |
164
- ------------------------ ------------ --------------------------------------------
38
+ TODO: in the present form, usage of the Java version of the parser
39
+ shouldn't be too difficult to figure out for someone familiar with the
40
+ C version.
165
41
 
42
+ More documentation will follow shortly, in case you're looking for an
43
+ easy to use http library, this lib is probably not what you are
44
+ looking for anyway ...
166
45
 
167
- See examples of reading in headers:
46
+ All text after this paragraph (and most of the text above it) are from
47
+ the original C version of the README and are currently only here for
48
+ reference. In case you encounter any difficulties, find bugs, need
49
+ help or have suggestions, feel free to contact me at
50
+ (tim.becker@kuriositaet.de).
168
51
 
169
- * [partial example](http://gist.github.com/155877) in C
170
- * [from http-parser tests](http://github.com/ry/http-parser/blob/37a0ff8928fb0d83cec0d0d8909c5a4abcd221af/test.c#L403) in C
171
- * [from Node library](http://github.com/ry/node/blob/842eaf446d2fdcb33b296c67c911c32a0dabc747/src/http.js#L284) in Javascript
@@ -1,3 +1,6 @@
1
+ some tests from test.c left to port
2
+ documentation
3
+
1
4
  hi level callback interface
2
5
  eventloop
3
6
  state() as a function (?)
@@ -0,0 +1,74 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <project name="http-parser" default="compile" basedir=".">
4
+
5
+ <echo message="pulling in property files"/>
6
+ <property file="build.properties"/>
7
+ <property name="classes.dir" value="classes"/>
8
+ <property name="assemble.dir" value="assemble"/>
9
+ <property name="lib.dir" value="lib"/>
10
+
11
+
12
+
13
+ <target name="prepare">
14
+ <mkdir dir="${classes.dir}" />
15
+ <mkdir dir="${assemble.dir}" />
16
+ <mkdir dir="${lib.dir}" />
17
+ </target>
18
+
19
+ <target name="clean">
20
+ <delete dir="${classes.dir}"/>
21
+ <delete dir="lib"/>
22
+ <delete dir="doc"/>
23
+ <delete dir="${assemble.dir}"/>
24
+ </target>
25
+
26
+ <target name="compile" depends="prepare">
27
+ <javac srcdir="src" destdir="${classes.dir}" debug='true'>
28
+ <classpath>
29
+ <pathelement path="${classpath}"/>
30
+ <pathelement location="ext/http-parser.jar"/>
31
+ <pathelement location="ext/primitives.jar"/>
32
+ </classpath>
33
+ </javac>
34
+ </target>
35
+
36
+ <target name="jar" depends="compile">
37
+ <copy todir="${assemble.dir}">
38
+ <fileset dir="classes"/>
39
+ </copy>
40
+ <jar basedir="${assemble.dir}" destfile="lib/${ant.project.name}.jar"/>
41
+ </target>
42
+
43
+ <target name="run" depends="jar">
44
+ <echo message="don't know how to run"/>
45
+ </target>
46
+
47
+ <target name="doc" depends="prepare">
48
+ <javadoc sourcepath="src/impl" destdir="doc">
49
+ </javadoc>
50
+ </target>
51
+
52
+ <target name="test_permutations" depends="compile">
53
+ <java classname="http_parser.lolevel.TestLoaderNG">
54
+ <arg value="tests.dumped"/>
55
+ <classpath>
56
+ <pathelement location="classes/"/>
57
+ <pathelement location="ext/primitives.jar/"/>
58
+ </classpath>
59
+ </java>
60
+ </target>
61
+
62
+ <target name="test_unit" depends="compile">
63
+ <java classname="http_parser.lolevel.Test">
64
+ <arg value="tests.dumped"/>
65
+ <classpath>
66
+ <pathelement location="classes/"/>
67
+ <pathelement location="ext/primitives.jar/"/>
68
+ </classpath>
69
+ </java>
70
+ </target>
71
+
72
+ <target name="test" depends="test_permutations, test_unit"/>
73
+
74
+ </project>