http 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of http might be problematic. Click here for more details.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +8 -0
- data/Rakefile +2 -0
- data/http.gemspec +17 -0
- data/lib/http.rb +5 -0
- data/lib/http/version.rb +3 -0
- data/parser/common.rl +40 -0
- data/parser/http.rl +220 -0
- data/parser/multipart.rl +41 -0
- metadata +66 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Tony Arcieri, Carl Lerche
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/http.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/http/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Tony Arcieri", "Carl Lerche"]
|
6
|
+
gem.email = ["tony.arcieri@gmail.com"]
|
7
|
+
gem.description = "HTTP so awesome it will lure Catherine Zeta Jones into your unicorn petting zoo"
|
8
|
+
gem.summary = "Made entirely of Ruby (and Ragel and C and Java)"
|
9
|
+
gem.homepage = "https://github.com/tarcieri/http"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "http"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Http::VERSION
|
17
|
+
end
|
data/lib/http.rb
ADDED
data/lib/http/version.rb
ADDED
data/parser/common.rl
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
%%{
|
2
|
+
|
3
|
+
machine common;
|
4
|
+
|
5
|
+
# ==== TOKENS ====
|
6
|
+
|
7
|
+
CRLF = "\r\n";
|
8
|
+
CTL = (cntrl | 127);
|
9
|
+
LWSP = " " | "\t";
|
10
|
+
LWS = CRLF ? LWSP *;
|
11
|
+
TEXT = any -- CTL;
|
12
|
+
LINE = TEXT -- CRLF;
|
13
|
+
separators = "(" | ")" | "<" | ">" | "@" | "," | ";"
|
14
|
+
| ":" | "\\" | "\"" | "/" | "[" | "]"
|
15
|
+
| "?" | "=" | "{" | "}" | " " | "\t"
|
16
|
+
;
|
17
|
+
token = TEXT -- separators;
|
18
|
+
|
19
|
+
# ==== HEADERS ====
|
20
|
+
|
21
|
+
header_sep = LWSP * ":" LWSP *;
|
22
|
+
header_eol = LWSP * CRLF;
|
23
|
+
ws_line = LWSP +;
|
24
|
+
no_ws_line = ( LINE -- LWSP ) + % end_header_value_no_ws;
|
25
|
+
blank_line = "" % end_header_value_no_ws;
|
26
|
+
non_blank_line = no_ws_line ( ws_line no_ws_line) * ws_line ?;
|
27
|
+
header_value_line = ( blank_line | non_blank_line )
|
28
|
+
> start_header_value_line
|
29
|
+
% end_header_value_line
|
30
|
+
;
|
31
|
+
|
32
|
+
header_value_line_1 = header_value_line CRLF;
|
33
|
+
header_value_line_n = LWSP + <: header_value_line_1;
|
34
|
+
header_value = header_value_line_1 header_value_line_n *;
|
35
|
+
generic_header_name = token +
|
36
|
+
> start_header_name
|
37
|
+
% end_header_name;
|
38
|
+
|
39
|
+
|
40
|
+
}%%
|
data/parser/http.rl
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
%%{
|
2
|
+
machine http;
|
3
|
+
|
4
|
+
include common "common.rl";
|
5
|
+
|
6
|
+
token_w_sp = token | " " | "\t";
|
7
|
+
quoted_str = "\"" ((any -- "\"") | ("\\" any)) * "\"";
|
8
|
+
parameter = token + "=" ( token + | quoted_str );
|
9
|
+
paramed_val = token * ( ";" ) ?;
|
10
|
+
|
11
|
+
# === HTTP methods
|
12
|
+
method = "HEAD" % method_head
|
13
|
+
| "GET" % method_get
|
14
|
+
| "POST" % method_post
|
15
|
+
| "PUT" % method_put
|
16
|
+
| "DELETE" % method_delete
|
17
|
+
| "CONNECT" % method_connect
|
18
|
+
| "OPTIONS" % method_options
|
19
|
+
| "TRACE" % method_trace
|
20
|
+
| "COPY" % method_copy
|
21
|
+
| "LOCK" % method_lock
|
22
|
+
| "MKCOL" % method_mkcol
|
23
|
+
| "MOVE" % method_move
|
24
|
+
| "PROPFIND" % method_propfind
|
25
|
+
| "PROPPATCH" % method_proppatch
|
26
|
+
| "UNLOCK" % method_unlock
|
27
|
+
| "REPORT" % method_report
|
28
|
+
| "MKACTIVITY" % method_mkactivity
|
29
|
+
| "CHECKOUT" % method_checkout
|
30
|
+
| "MERGE" % method_merge
|
31
|
+
| "MSEARCH" % method_msearch
|
32
|
+
| "NOTIFY" % method_notify
|
33
|
+
| "SUBSCRIBE" % method_subscribe
|
34
|
+
| "UNSUBSCRIBE" % method_unsubscribe
|
35
|
+
| "PATCH" % method_patch
|
36
|
+
;
|
37
|
+
|
38
|
+
# === HTTP request URI
|
39
|
+
request_uri = ( TEXT -- LWSP ) +
|
40
|
+
> start_uri
|
41
|
+
% end_uri;
|
42
|
+
|
43
|
+
# === HTTP version
|
44
|
+
http_version = ( "HTTP/"i ( digit + $ http_major ) "."
|
45
|
+
( digit + $ http_minor ) )
|
46
|
+
> start_version;
|
47
|
+
|
48
|
+
|
49
|
+
# === HTTP headers
|
50
|
+
|
51
|
+
header_name = "accept"i % hn_accept
|
52
|
+
| "accept-charset"i % hn_accept_charset
|
53
|
+
| "accept-encoding"i % hn_accept_encoding
|
54
|
+
| "accept-language"i % hn_accept_language
|
55
|
+
| "accept-ranges"i % hn_accept_ranges
|
56
|
+
| "age"i % hn_age
|
57
|
+
| "allow"i % hn_allow
|
58
|
+
| "authorization"i % hn_authorization
|
59
|
+
| "cache-control"i % hn_cache_control
|
60
|
+
| "connection"i % hn_connection
|
61
|
+
| "content-encoding"i % hn_content_encoding
|
62
|
+
| "content-language"i % hn_content_language
|
63
|
+
| "content-length"i % hn_content_length
|
64
|
+
| "content-location"i % hn_content_location
|
65
|
+
| "content-md5"i % hn_content_md5
|
66
|
+
| "content-disposition"i % hn_content_disposition
|
67
|
+
| "content-range"i % hn_content_range
|
68
|
+
| "content-type"i % hn_content_type
|
69
|
+
| "cookie"i % hn_cookie
|
70
|
+
| "date"i % hn_date
|
71
|
+
| "dnt"i % hn_dnt
|
72
|
+
| "etag"i % hn_etag
|
73
|
+
| "expect"i % hn_expect
|
74
|
+
| "expires"i % hn_expires
|
75
|
+
| "from"i % hn_from
|
76
|
+
| "host"i % hn_host
|
77
|
+
| "if-match"i % hn_if_match
|
78
|
+
| "if-modified-since"i % hn_if_modified_since
|
79
|
+
| "if-none-match"i % hn_if_none_match
|
80
|
+
| "if-range"i % hn_if_range
|
81
|
+
| "if-unmodified-since"i % hn_if_unmodified_since
|
82
|
+
| "keep-alive"i % hn_keep_alive
|
83
|
+
| "last-modified"i % hn_last_modified
|
84
|
+
| "link"i % hn_link
|
85
|
+
| "location"i % hn_location
|
86
|
+
| "max-forwards"i % hn_max_forwards
|
87
|
+
| "p3p"i % hn_p3p
|
88
|
+
| "pragma"i % hn_pragma
|
89
|
+
| "proxy-authenticate"i % hn_proxy_authenticate
|
90
|
+
| "proxy-authorization"i % hn_proxy_authorization
|
91
|
+
| "range"i % hn_range
|
92
|
+
| "referer"i % hn_referer
|
93
|
+
| "refresh"i % hn_refresh
|
94
|
+
| "retry-after"i % hn_retry_after
|
95
|
+
| "server"i % hn_server
|
96
|
+
| "set-cookie"i % hn_set_cookie
|
97
|
+
| "strict-transport-security"i % hn_strict_transport_security
|
98
|
+
| "te"i % hn_te
|
99
|
+
| "trailer"i % hn_trailer
|
100
|
+
| "transfer-encoding"i % hn_transfer_encoding
|
101
|
+
| "upgrade"i % hn_upgrade
|
102
|
+
| "user-agent"i % hn_user_agent
|
103
|
+
| "vary"i % hn_vary
|
104
|
+
| "via"i % hn_via
|
105
|
+
| "warning"i % hn_warning
|
106
|
+
| "www-authenticate"i % hn_www_authenticate
|
107
|
+
| "x-content-type-options"i % hn_x_content_type_options
|
108
|
+
| "x-do-not-track"i % hn_x_do_not_track
|
109
|
+
| "x-forwarded-for"i % hn_x_forwarded_for
|
110
|
+
| "x-forwarded-proto"i % hn_x_forwarded_proto
|
111
|
+
| "x-frame-options"i % hn_x_frame_options
|
112
|
+
| "x-powered-by"i % hn_x_powered_by
|
113
|
+
| "x-requested-with"i % hn_x_requested_with
|
114
|
+
| "x-xss-protection"i % hn_x_xss_protection
|
115
|
+
| generic_header_name
|
116
|
+
;
|
117
|
+
|
118
|
+
hdr_generic = header_name
|
119
|
+
header_sep
|
120
|
+
header_value
|
121
|
+
% end_header_value;
|
122
|
+
|
123
|
+
|
124
|
+
# Header: Content-Length
|
125
|
+
# ===
|
126
|
+
#
|
127
|
+
content_length_val = digit +
|
128
|
+
$ count_content_length
|
129
|
+
% end_content_length
|
130
|
+
;
|
131
|
+
|
132
|
+
hdr_content_length = "content-length"i
|
133
|
+
header_sep
|
134
|
+
content_length_val $lerr(content_length_err)
|
135
|
+
header_eol;
|
136
|
+
|
137
|
+
# Header: Transfer-Encoding
|
138
|
+
# ===
|
139
|
+
#
|
140
|
+
hdr_transfer_encoding = "transfer-encoding"i
|
141
|
+
header_sep
|
142
|
+
"chunked"i
|
143
|
+
% end_transfer_encoding_chunked
|
144
|
+
header_eol;
|
145
|
+
|
146
|
+
# Header: Connection
|
147
|
+
# ===
|
148
|
+
# This probably isn't completely right since mutliple tokens
|
149
|
+
# are permitted in the Connection header.
|
150
|
+
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10
|
151
|
+
#
|
152
|
+
hdr_connection = "connection"i
|
153
|
+
header_sep
|
154
|
+
( "close"i % end_connection_close
|
155
|
+
| "upgrade"i % end_connection_upgrade )
|
156
|
+
header_eol;
|
157
|
+
|
158
|
+
# Header: Expect
|
159
|
+
# ===
|
160
|
+
#
|
161
|
+
hdr_expect = "expect"i
|
162
|
+
header_sep
|
163
|
+
"100-continue"i
|
164
|
+
% end_expect_continue
|
165
|
+
header_eol;
|
166
|
+
|
167
|
+
header = hdr_content_length
|
168
|
+
| hdr_transfer_encoding
|
169
|
+
| hdr_connection
|
170
|
+
| hdr_expect
|
171
|
+
| hdr_generic
|
172
|
+
;
|
173
|
+
|
174
|
+
headers = header *;
|
175
|
+
|
176
|
+
# === HTTP head
|
177
|
+
request_line = method " " + request_uri ( " " + http_version ) ? CRLF;
|
178
|
+
exchange_head = ( CRLF * request_line headers CRLF )
|
179
|
+
> start_head
|
180
|
+
@ end_head;
|
181
|
+
|
182
|
+
# === HTTP chunked body
|
183
|
+
chunk_ext = ";" TEXT *;
|
184
|
+
last_chunk = '0' + chunk_ext ? CRLF;
|
185
|
+
chunk_size = ( xdigit + - '0' + )
|
186
|
+
> start_chunk_size
|
187
|
+
$ count_chunk_size
|
188
|
+
$! chunk_size_err;
|
189
|
+
|
190
|
+
chunk_head = chunk_size chunk_ext ? CRLF;
|
191
|
+
chunk_body = any
|
192
|
+
$ handle_chunk
|
193
|
+
when handling_body;
|
194
|
+
|
195
|
+
chunk_tail = last_chunk
|
196
|
+
% last_chunk
|
197
|
+
( TEXT + CRLF ) *;
|
198
|
+
|
199
|
+
chunk = chunk_head chunk_body * <: CRLF;
|
200
|
+
|
201
|
+
chunked_body := ( chunk + chunk_tail CRLF )
|
202
|
+
%to(reset)
|
203
|
+
$! something_went_wrong;
|
204
|
+
|
205
|
+
# === HTTP identity body
|
206
|
+
identity_chunk = any
|
207
|
+
$ handle_body
|
208
|
+
when handling_body;
|
209
|
+
|
210
|
+
identity_body := identity_chunk *
|
211
|
+
$! something_went_wrong;
|
212
|
+
|
213
|
+
# === Upgraded connections
|
214
|
+
upgraded := any * $ handle_message;
|
215
|
+
|
216
|
+
main := exchange_head +
|
217
|
+
$ count_message_head
|
218
|
+
$err(something_went_wrong);
|
219
|
+
|
220
|
+
}%%
|
data/parser/multipart.rl
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
%%{
|
2
|
+
|
3
|
+
machine multipart;
|
4
|
+
|
5
|
+
include common "common.rl";
|
6
|
+
|
7
|
+
bchar = alnum | "'" | "(" | ")" | "+" | "_" | ","
|
8
|
+
| "-" | "." | "/" | ":" | "=" | "?"
|
9
|
+
;
|
10
|
+
|
11
|
+
|
12
|
+
final = "--" @ end_parts ;
|
13
|
+
padding = final ? LWSP * CRLF;
|
14
|
+
|
15
|
+
# ==== HEADERS ====
|
16
|
+
header_name = generic_header_name;
|
17
|
+
header = header_name header_sep header_value % end_header_value;
|
18
|
+
headers = header * CRLF;
|
19
|
+
|
20
|
+
multipart =
|
21
|
+
start:
|
22
|
+
any * $ peek_delimiter,
|
23
|
+
|
24
|
+
delimiter:
|
25
|
+
any * $ parse_delimiter,
|
26
|
+
|
27
|
+
head:
|
28
|
+
padding
|
29
|
+
headers
|
30
|
+
> start_head
|
31
|
+
% end_head
|
32
|
+
-> body,
|
33
|
+
|
34
|
+
body:
|
35
|
+
any * $ peek_delimiter,
|
36
|
+
|
37
|
+
epilogue: any *;
|
38
|
+
|
39
|
+
main := multipart $! something_went_wrong;
|
40
|
+
|
41
|
+
}%%
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tony Arcieri
|
9
|
+
- Carl Lerche
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-10-06 00:00:00 Z
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: HTTP so awesome it will lure Catherine Zeta Jones into your unicorn petting zoo
|
18
|
+
email:
|
19
|
+
- tony.arcieri@gmail.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- LICENSE.txt
|
30
|
+
- README.md
|
31
|
+
- Rakefile
|
32
|
+
- http.gemspec
|
33
|
+
- lib/http.rb
|
34
|
+
- lib/http/version.rb
|
35
|
+
- parser/common.rl
|
36
|
+
- parser/http.rl
|
37
|
+
- parser/multipart.rl
|
38
|
+
homepage: https://github.com/tarcieri/http
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Made entirely of Ruby (and Ragel and C and Java)
|
65
|
+
test_files: []
|
66
|
+
|