tilia-http 4.1.0.8 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tilia/http.rb CHANGED
@@ -56,9 +56,9 @@ module Tilia
56
56
  # http://tools.ietf.org/html/rfc7231#section-7.1.1.1
57
57
  #
58
58
  # @param [String] date_string
59
- # @return bool|DateTime
59
+ # @return [Time, nil]
60
60
  def self.parse_date(date_string)
61
- return false unless date_string
61
+ return nil if date_string.blank?
62
62
 
63
63
  # Only the format is checked, valid ranges are checked by strtotime below
64
64
  month = '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)'
@@ -83,7 +83,7 @@ module Tilia
83
83
  # allow for space around the string and strip it
84
84
  date_string.strip!
85
85
 
86
- return false unless date_string =~ /^#{http_date}$/
86
+ return nil unless date_string =~ /^#{http_date}$/
87
87
 
88
88
  date = Time.zone.parse date_string
89
89
 
@@ -112,7 +112,7 @@ module Tilia
112
112
 
113
113
  # Transforms a DateTime object to a valid HTTP/1.1 Date header value
114
114
  #
115
- # @param DateTime date_time
115
+ # @param [Time] date_time
116
116
  # @return [String]
117
117
  def self.to_date(date_time)
118
118
  # We need to clone it, as we don't want to affect the existing
@@ -136,10 +136,10 @@ module Tilia
136
136
  # implying that no accept header was sent.
137
137
  #
138
138
  # @param [String, nil] accept_header_value
139
- # @param array available_options
139
+ # @param [Array<String>] available_options
140
140
  # @return [String, nil]
141
141
  def self.negotiate_content_type(accept_header_value, available_options)
142
- unless accept_header_value
142
+ if accept_header_value.blank?
143
143
  # Grabbing the first in the list.
144
144
  return available_options[0]
145
145
  end
@@ -223,7 +223,7 @@ module Tilia
223
223
  # Parameters are currently discarded. There's no known prefer value that
224
224
  # uses them.
225
225
  #
226
- # @param [String, Array<String>] header
226
+ # @param [String, Array<String>] input
227
227
  # @return array
228
228
  def self.parse_prefer(input)
229
229
  token = '[!#$%&\'*+\-.^_`~A-Za-z0-9]+'
@@ -287,7 +287,7 @@ $
287
287
  #
288
288
  # @param [String, Array<String>] values
289
289
  # @param [String, Array<String>] values2
290
- # @return [String][]
290
+ # @return [Array<String>]
291
291
  def self.header_values(values, values2 = nil)
292
292
  values = [values] unless values.is_a?(Array)
293
293
  if values2
@@ -313,7 +313,7 @@ $
313
313
  # 4. parameters
314
314
  #
315
315
  # @param [String] str
316
- # @return array
316
+ # @return [Hash, nil]
317
317
  def self.parse_mime_type(str)
318
318
  parameters = {}
319
319
  # If no q= parameter appears, then quality = 1.
@@ -36,6 +36,30 @@ module Tilia
36
36
  assert_equal(body, message.body)
37
37
  end
38
38
 
39
+ # It's possible that streams contains more data than the Content-Length.
40
+ #
41
+ # The request object should make sure to never emit more than
42
+ # Content-Length, if Content-Length is set.
43
+ #
44
+ # This is in particular useful when respoding to range requests with
45
+ # streams that represent files on the filesystem, as it's possible to just
46
+ # seek the stream to a certain point, set the content-length and let the
47
+ # request object do the rest.
48
+ def test_long_stream_to_string_body
49
+ body = StringIO.new
50
+ body.write('abcdefg')
51
+ body.seek(2)
52
+
53
+ message = MessageMock.new
54
+ message.body = body
55
+ message.update_header('Content-Length', '4')
56
+
57
+ assert_equal(
58
+ 'cdef',
59
+ message.body_as_string
60
+ )
61
+ end
62
+
39
63
  def test_get_empty_body_stream
40
64
  message = MessageMock.new
41
65
  body = message.body_as_stream
@@ -154,10 +178,6 @@ module Tilia
154
178
 
155
179
  class MessageMock
156
180
  include Message
157
-
158
- def initialize
159
- initialize_message
160
- end
161
181
  end
162
182
  end
163
183
  end
@@ -129,7 +129,7 @@ module Tilia
129
129
  'foo/' => ['', 'foo'],
130
130
  '/foo/' => ['', 'foo'],
131
131
  '/foo' => ['', 'foo'],
132
- '' => [nil, nil],
132
+ '' => ['', ''],
133
133
 
134
134
  # UTF-8
135
135
  "/\xC3\xA0fo\xC3\xB3/bar" => ["/\xC3\xA0fo\xC3\xB3", 'bar'],
data/tilia-http.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = 'tilia@jakobsack.de'
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.homepage = 'https://github.com/tilia/tilia-http'
12
- s.add_runtime_dependency 'activesupport', '~> 4.2'
12
+ s.add_runtime_dependency 'activesupport', '>= 4.0'
13
13
  s.add_runtime_dependency 'typhoeus', '~> 0.8'
14
14
  s.add_runtime_dependency 'rchardet', '~>1.6'
15
15
  s.add_runtime_dependency 'tilia-event', '~> 2.0'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tilia-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.8
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Sack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-03 00:00:00.000000000 Z
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: typhoeus
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ files:
119
119
  - examples/asyncclient.rb
120
120
  - examples/basicauth.rb
121
121
  - examples/client.rb
122
+ - examples/digestauth.rb
122
123
  - examples/reverseproxy.rb
123
124
  - examples/stringify.rb
124
125
  - lib/tilia/http.rb