http 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGES.md +13 -0
- data/README.md +17 -12
- data/lib/http/content_type.rb +4 -4
- data/lib/http/request/writer.rb +2 -2
- data/lib/http/version.rb +1 -1
- data/spec/lib/http_spec.rb +13 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f055f29a48247045d37ed9be74484f3116d0c1
|
4
|
+
data.tar.gz: de2b1a88f332b6f2c1848f85b1ff3fe6d01ba49d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3f82de8ae1a6947a667216d9cb865eef7c18d068384db44fde9bb8c4c81db2fbf6f36161b559306e9822bdf1186b61cc1053789ebfc9787c7a4179c54a40f47
|
7
|
+
data.tar.gz: 0d8c22f1fa37b8da65a978cd82ca4f7fa42dd52c9307232c2df329f27b046aa14d9f91445197e1018de761d6ce9e5c8e2379f8e0530b7d938fbe4a4e61878328
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 2.0.1 (2016-05-12)
|
2
|
+
|
3
|
+
* [#341](https://github.com/httprb/http/pull/341)
|
4
|
+
Refactor some string manipulations so they are more performant
|
5
|
+
(up to 3-4x faster) and more concise.
|
6
|
+
([@tonyta])
|
7
|
+
|
8
|
+
* [#339](https://github.com/httprb/http/pull/341)
|
9
|
+
Always use byte methods when writing/slicing the write buffer.
|
10
|
+
([@zanker])
|
11
|
+
|
12
|
+
|
1
13
|
## 2.0.0 (2016-04-23)
|
2
14
|
|
3
15
|
* [#333](https://github.com/httprb/http/pull/333)
|
@@ -516,3 +528,4 @@ end
|
|
516
528
|
[@kylekyle]: https://github.com/kylekyle
|
517
529
|
[@smudge]: https://github.com/smudge
|
518
530
|
[@mwitek]: https://github.com/mwitek
|
531
|
+
[@tonyta]: https://github.com/tonyta
|
data/README.md
CHANGED
@@ -117,35 +117,40 @@ Here's some simple examples to get you started:
|
|
117
117
|
|
118
118
|
```ruby
|
119
119
|
>> HTTP.get("https://github.com").to_s
|
120
|
-
=> "<html
|
120
|
+
=> "\n\n\n<!DOCTYPE html>\n<html lang=\"en\" class=\"\">\n <head prefix=\"o..."
|
121
121
|
```
|
122
122
|
|
123
123
|
That's all it takes! To obtain an `HTTP::Response` object instead of the response
|
124
|
-
body, all we have to do is omit the
|
124
|
+
body, all we have to do is omit the `#to_s` on the end:
|
125
125
|
|
126
126
|
```ruby
|
127
127
|
>> HTTP.get("https://github.com")
|
128
|
-
=> #<HTTP/1.
|
129
|
-
=> #<HTTP::Response/1.1 200 OK @headers={"Content-Type"=>"text/html; ...>
|
128
|
+
=> #<HTTP::Response/1.1 200 OK {"Server"=>"GitHub.com", "Date"=>"Tue, 10 May...>
|
130
129
|
```
|
131
130
|
|
132
131
|
We can also obtain an `HTTP::Response::Body` object for this response:
|
133
132
|
|
134
133
|
```ruby
|
135
134
|
>> HTTP.get("https://github.com").body
|
136
|
-
|
135
|
+
=> #<HTTP::Response::Body:3ff756862b48 @streaming=false>
|
137
136
|
```
|
138
137
|
|
139
|
-
The response body can be streamed with `HTTP::Response::Body#readpartial
|
138
|
+
The response body can be streamed with `HTTP::Response::Body#readpartial`.
|
139
|
+
In practice, you'll want to bind the HTTP::Response::Body to a local variable
|
140
|
+
and call `#readpartial` on it repeatedly until it returns `nil`:
|
140
141
|
|
141
142
|
```ruby
|
142
|
-
>> HTTP.get("https://github.com").body
|
143
|
-
|
143
|
+
>> body = HTTP.get("https://github.com").body
|
144
|
+
=> #<HTTP::Response::Body:3ff756862b48 @streaming=false>
|
145
|
+
>> body.readpartial
|
146
|
+
=> "\n\n\n<!DOCTYPE html>\n<html lang=\"en\" class=\"\">\n <head prefix=\"o..."
|
147
|
+
>> body.readpartial
|
148
|
+
=> "\" href=\"/apple-touch-icon-72x72.png\">\n <link rel=\"apple-touch-ic..."
|
149
|
+
# ...
|
150
|
+
>> body.readpartial
|
151
|
+
=> nil
|
144
152
|
```
|
145
153
|
|
146
|
-
In practice you'll want to bind the HTTP::Response::Body to a local variable (e.g.
|
147
|
-
"body") and call readpartial on it repeatedly until it returns `nil`.
|
148
|
-
|
149
154
|
## Supported Ruby Versions
|
150
155
|
|
151
156
|
This library aims to support and is [tested against][travis] the following Ruby
|
@@ -155,7 +160,7 @@ versions:
|
|
155
160
|
* Ruby 2.1.x
|
156
161
|
* Ruby 2.2.x
|
157
162
|
* Ruby 2.3.x
|
158
|
-
* JRuby 9.0.
|
163
|
+
* JRuby 9.1.0.0
|
159
164
|
|
160
165
|
If something doesn't work on one of these versions, it's a bug.
|
161
166
|
|
data/lib/http/content_type.rb
CHANGED
@@ -13,14 +13,14 @@ module HTTP
|
|
13
13
|
|
14
14
|
# :nodoc:
|
15
15
|
def mime_type(str)
|
16
|
-
|
17
|
-
|
16
|
+
m = str.to_s[MIME_TYPE_RE, 1]
|
17
|
+
m && m.strip.downcase
|
18
18
|
end
|
19
19
|
|
20
20
|
# :nodoc:
|
21
21
|
def charset(str)
|
22
|
-
|
23
|
-
|
22
|
+
m = str.to_s[CHARSET_RE, 1]
|
23
|
+
m && m.strip.delete('"')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/http/request/writer.rb
CHANGED
data/lib/http/version.rb
CHANGED
data/spec/lib/http_spec.rb
CHANGED
@@ -64,7 +64,19 @@ RSpec.describe HTTP do
|
|
64
64
|
response = client.post("#{dummy.endpoint}/echo-body", :body => request_body)
|
65
65
|
|
66
66
|
expect(response.body.to_s).to eq(request_body)
|
67
|
-
expect(response.headers["Content-Length"].to_i).to eq(request_body.
|
67
|
+
expect(response.headers["Content-Length"].to_i).to eq(request_body.bytesize)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when bytesize != length" do
|
71
|
+
let(:characters) { ("A".."Z").to_a.push("“") }
|
72
|
+
|
73
|
+
it "returns a large body" do
|
74
|
+
body = {:data => request_body}
|
75
|
+
response = client.post("#{dummy.endpoint}/echo-body", :json => body)
|
76
|
+
|
77
|
+
expect(CGI.unescape(response.body.to_s)).to eq(body.to_json)
|
78
|
+
expect(response.headers["Content-Length"].to_i).to eq(body.to_json.bytesize)
|
79
|
+
end
|
68
80
|
end
|
69
81
|
end
|
70
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: http_parser.rb
|