hobbit 0.4.2 → 0.4.3

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: b7c486fc3d4a7a9ab2cf164da150c53e64dfea84
4
- data.tar.gz: 1cd83cd0025ac0f255972ec361e644b2bcd3342f
3
+ metadata.gz: fc695229b6dbea81ceaf3de386769ca9dff5ded5
4
+ data.tar.gz: f5444f4ca2eeb0edd6929bfe7058476a75690972
5
5
  SHA512:
6
- metadata.gz: aaaafbb99b619a7f4553c03183732e02c3a054977e21de5ac60e0078e73bddbbe8c3558b3d173bb119dd04beb7d941a33ed3b062f036a47973cad15ac77d6cbc
7
- data.tar.gz: 240d21c02bc59f9e3a6916540d8b24b2d4bf7812786302a1e3f399a55af9ed0273cfef0e75124fe26bf4ba36c31cbba711f8b20934edf1c0807a6d4ad0676a52
6
+ metadata.gz: 6c7d75254bd0ae03006229ed7f665548eb7a5557dbdc0a866910d4ebf7aa9840b7bb2dcc93ec15d2f839219310ffc0e14b4ef2a7ac4b1449fc0a4b2ec0098af6
7
+ data.tar.gz: 4e5519917bbee84db20e22de8208e9776ec5bdeaef48b88c03f0158151373029ed695e015df5476e9ed34ca6e63b4dc1077bbdd6ab209949d8ed08c678643ca3
@@ -1,3 +1,8 @@
1
+ # 0.4.3
2
+
3
+ * Calculate the `Content-Length` of a `Hobbit::Response` using `#bytesize`
4
+ instead of `#size`.
5
+
1
6
  # 0.4.2
2
7
 
3
8
  * Add `Hobbit::Response#redirect`, that was missing since `Hobbit::Response`
data/README.md CHANGED
@@ -27,7 +27,7 @@ $ gem install hobbit
27
27
  ## Features
28
28
 
29
29
  * DSL inspired by [Sinatra](http://www.sinatrarb.com/).
30
- * [Speed](https://github.com/patriciomacadden/microbenchmarks).
30
+ * [Speed](https://github.com/luislavena/bench-micro).
31
31
  * Extensible with standard ruby classes and modules, with no extra logic. See
32
32
  [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib).
33
33
  * Zero configuration.
@@ -174,65 +174,46 @@ class App < Hobbit::Base
174
174
  end
175
175
  ```
176
176
 
177
- ### Built on top of rack
178
-
179
- Each Hobbit application is a Rack stack (See this
180
- [blog post](http://m.onkey.org/ruby-on-rack-2-the-builder) for more
181
- information).
182
-
183
- #### Mapping applications
177
+ #### Halting
184
178
 
185
- You can mount any Rack application to the stack by using the `map` class
186
- method:
179
+ To immediately stop a request within a filter or route you must specify the
180
+ status:
187
181
 
188
182
  ```ruby
189
183
  require 'hobbit'
190
184
 
191
- class InnerApp < Hobbit::Base
192
- # gets called when path_info = '/inner'
193
- get do
194
- 'Hello InnerApp!'
195
- end
196
- end
197
-
198
185
  class App < Hobbit::Base
199
- map('/inner') { run InnerApp.new }
186
+ use Rack::Session::Cookie, secret: SecureRandom.hex(64)
187
+
188
+ def session
189
+ env['rack.session']
190
+ end
200
191
 
201
192
  get '/' do
202
- 'Hello App!'
193
+ halt 401 unless session['user_id']
203
194
  end
204
195
  end
205
196
  ```
206
197
 
207
- #### Using middleware
208
-
209
- You can add any Rack middleware to the stack by using the `use` class method:
198
+ And also you can add a body:
210
199
 
211
200
  ```ruby
212
201
  require 'hobbit'
213
202
 
214
203
  class App < Hobbit::Base
215
204
  use Rack::Session::Cookie, secret: SecureRandom.hex(64)
216
- use Rack::ShowExceptions
217
205
 
218
206
  def session
219
207
  env['rack.session']
220
208
  end
221
209
 
222
210
  get '/' do
223
- session[:name] = 'hobbit'
211
+ halt 401, body: 'This will be the body' unless session['user_id']
224
212
  end
225
-
226
- # more routes...
227
213
  end
228
-
229
- run App.new
230
214
  ```
231
215
 
232
- #### Halting
233
-
234
- To immediately stop a request within a filter or route you must specify the
235
- status:
216
+ Or headers:
236
217
 
237
218
  ```ruby
238
219
  require 'hobbit'
@@ -245,14 +226,14 @@ class App < Hobbit::Base
245
226
  end
246
227
 
247
228
  get '/' do
248
- halt 401 unless session['user_id']
229
+ halt 401, headers: { 'Content-Type' => 'text/html; charset=utf-8' }
249
230
  end
250
231
  end
251
232
  ```
252
233
 
253
- And also you can add a body:
234
+ Or both:
254
235
 
255
- ```ruby
236
+ ``` ruby
256
237
  require 'hobbit'
257
238
 
258
239
  class App < Hobbit::Base
@@ -263,45 +244,64 @@ class App < Hobbit::Base
263
244
  end
264
245
 
265
246
  get '/' do
266
- halt 401, body: 'This will be the body' unless session['user_id']
247
+ halt 401, headers: { 'Content-Type' => 'text/html; charset=utf-8' }, body: 'Woops'
267
248
  end
268
249
  end
269
250
  ```
270
251
 
271
- Or headers:
252
+ ### Built on top of rack
253
+
254
+ Each Hobbit application is a Rack stack (See this
255
+ [blog post](http://m.onkey.org/ruby-on-rack-2-the-builder) for more
256
+ information).
257
+
258
+ #### Mapping applications
259
+
260
+ You can mount any Rack application to the stack by using the `map` class
261
+ method:
272
262
 
273
263
  ```ruby
274
264
  require 'hobbit'
275
265
 
276
- class App < Hobbit::Base
277
- use Rack::Session::Cookie, secret: SecureRandom.hex(64)
278
-
279
- def session
280
- env['rack.session']
266
+ class InnerApp < Hobbit::Base
267
+ # gets called when path_info = '/inner'
268
+ get do
269
+ 'Hello InnerApp!'
281
270
  end
271
+ end
272
+
273
+ class App < Hobbit::Base
274
+ map('/inner') { run InnerApp.new }
282
275
 
283
276
  get '/' do
284
- halt 401, headers: { 'Content-Type' => 'text/html; charset=utf-8' }
277
+ 'Hello App!'
285
278
  end
286
279
  end
287
280
  ```
288
281
 
289
- Or both:
282
+ #### Using middleware
290
283
 
291
- ``` ruby
284
+ You can add any Rack middleware to the stack by using the `use` class method:
285
+
286
+ ```ruby
292
287
  require 'hobbit'
293
288
 
294
289
  class App < Hobbit::Base
295
290
  use Rack::Session::Cookie, secret: SecureRandom.hex(64)
291
+ use Rack::ShowExceptions
296
292
 
297
293
  def session
298
294
  env['rack.session']
299
295
  end
300
296
 
301
297
  get '/' do
302
- halt 401, headers: { 'Content-Type' => 'text/html; charset=utf-8' }, body: 'Woops'
298
+ session[:name] = 'hobbit'
303
299
  end
300
+
301
+ # more routes...
304
302
  end
303
+
304
+ run App.new
305
305
  ```
306
306
 
307
307
  ### Security
@@ -11,17 +11,17 @@ module Hobbit
11
11
  end
12
12
 
13
13
  def finish
14
- headers['Content-Length'] = body.each.map(&:size).inject { |memo, current| memo += current }.to_s
14
+ headers['Content-Length'] = body.each.map { |i| i.is_a?(Array) ? i.map(&:to_s).map(&:bytesize) : i.bytesize }.flatten.inject(0, &:+).to_s
15
15
  [status, headers, body]
16
16
  end
17
17
 
18
18
  def redirect(target, status = 302)
19
- headers['Location'] = target
20
19
  self.status = status
20
+ headers['Location'] = target
21
21
  end
22
22
 
23
23
  def write(string)
24
- self.body << string
24
+ body << string
25
25
  end
26
26
  end
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module Hobbit
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -231,9 +231,9 @@ EOS
231
231
  end
232
232
  end
233
233
 
234
- it 'return the response given to halt function' do
234
+ it 'returns the response given to halt function' do
235
235
  get '/halt'
236
- last_response.headers.must_equal({ 'Content-Length' => '' })
236
+ last_response.headers.must_equal({ 'Content-Length' => '0' })
237
237
  last_response.body.must_equal ''
238
238
  last_response.status.must_equal 501
239
239
  end
@@ -258,7 +258,7 @@ EOS
258
258
 
259
259
  it 'accepts headers' do
260
260
  get '/halt_headers'
261
- last_response.headers.must_equal({ header: 'OK', 'Content-Length' => '' })
261
+ last_response.headers.must_equal({ header: 'OK', 'Content-Length' => '0' })
262
262
  last_response.status.must_equal 501
263
263
  end
264
264
  end
@@ -61,6 +61,13 @@ describe Hobbit::Response do
61
61
  h.must_include 'Content-Length'
62
62
  h['Content-Length'].must_equal '17'
63
63
  end
64
+
65
+ it 'must calculate the Content-Length of the body, even if the body is empty' do
66
+ response = Hobbit::Response.new
67
+ s, h, b = response.finish
68
+ h.must_include 'Content-Length'
69
+ h['Content-Length'].must_equal '0'
70
+ end
64
71
  end
65
72
 
66
73
  describe '#redirect' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Mac Adden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-29 00:00:00.000000000 Z
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler