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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ae83a6df13ab671375cfdd322ba65d1a15b8a43
4
- data.tar.gz: 4e107db57baa353e23fb25d805a3a0a6f17d1310
3
+ metadata.gz: 21f055f29a48247045d37ed9be74484f3116d0c1
4
+ data.tar.gz: de2b1a88f332b6f2c1848f85b1ff3fe6d01ba49d
5
5
  SHA512:
6
- metadata.gz: fdc5e4ea2f1e56a213246c34b40320584a1e092d07fcb03f99dd9f11d260b81e40be26483640a997c57d601b4882c753ca367152bd7cca9ad5b0498cb1b6681b
7
- data.tar.gz: e421f13bb1522ec92bd2eca7efd73a713036daba084416cdc86d69d681d72d8f050738fe9b664d101a186afb028dd0d46eea475c029587a17d3dc3dfa619ac21
6
+ metadata.gz: e3f82de8ae1a6947a667216d9cb865eef7c18d068384db44fde9bb8c4c81db2fbf6f36161b559306e9822bdf1186b61cc1053789ebfc9787c7a4179c54a40f47
7
+ data.tar.gz: 0d8c22f1fa37b8da65a978cd82ca4f7fa42dd52c9307232c2df329f27b046aa14d9f91445197e1018de761d6ce9e5c8e2379f8e0530b7d938fbe4a4e61878328
@@ -12,7 +12,7 @@ rvm:
12
12
  - 2.1
13
13
  - 2.2
14
14
  - 2.3.0
15
- - jruby-9.0.5.0
15
+ - jruby-9.1.0.0
16
16
  - jruby-head
17
17
  - ruby-head
18
18
  - rbx-2
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><head><meta http-equiv=\"content-type\" content=..."
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 #to_s on the end:
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.0 200 OK @headers={"Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Fri, ...>
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
- => #<HTTP::Response::Body:814d7aac @streaming=false>
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.readpartial
143
- => "<!doctype html><html "
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.5.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
 
@@ -13,14 +13,14 @@ module HTTP
13
13
 
14
14
  # :nodoc:
15
15
  def mime_type(str)
16
- md = str.to_s.match MIME_TYPE_RE
17
- md && md[1].to_s.strip.downcase
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
- md = str.to_s.match CHARSET_RE
23
- md && md[1].to_s.strip.gsub(/^"|"$/, "")
22
+ m = str.to_s[CHARSET_RE, 1]
23
+ m && m.strip.delete('"')
24
24
  end
25
25
  end
26
26
  end
@@ -95,8 +95,8 @@ module HTTP
95
95
  def write(data)
96
96
  until data.empty?
97
97
  length = @socket.write(data)
98
- break unless data.length > length
99
- data = data[length..-1]
98
+ break unless data.bytesize > length
99
+ data = data.byteslice(length..-1)
100
100
  end
101
101
  end
102
102
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module HTTP
3
- VERSION = "2.0.0".freeze
3
+ VERSION = "2.0.1".freeze
4
4
  end
@@ -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.length)
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.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-04-23 00:00:00.000000000 Z
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