jellyfish 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/jellyfish.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Jellyfish
3
4
  autoload :VERSION , 'jellyfish/version'
@@ -10,16 +11,22 @@ module Jellyfish
10
11
  autoload :ChunkedBody, 'jellyfish/chunked_body'
11
12
  autoload :WebSocket , 'jellyfish/websocket'
12
13
 
13
- Cascade = Object.new
14
- GetValue = Object.new
14
+ Cascade = Object.new.freeze
15
+ GetValue = Object.new.freeze
15
16
 
16
17
  class Response < RuntimeError
18
+ def self.contents status
19
+ (@contents ||= Hash.new do |hash, key|
20
+ hash[key] = File.read("#{Jellyfish.public_root}/#{status}.html")
21
+ end)[status]
22
+ end
23
+
17
24
  def headers
18
- @headers ||= {'Content-Type' => 'text/html'}
25
+ @headers ||= {'content-type' => 'text/html'}
19
26
  end
20
27
 
21
28
  def body
22
- @body ||= [File.read("#{Jellyfish.public_root}/#{status}.html")]
29
+ @body ||= [self.class.contents(status)]
23
30
  end
24
31
  end
25
32
 
@@ -29,9 +36,10 @@ module Jellyfish
29
36
  attr_reader :url
30
37
  def initialize url; @url = url ; end
31
38
  def status ; 302 ; end
32
- def headers ; super.merge('Location' => url) ; end
33
- def body ; super.map{ |b| b.gsub('VAR_URL', url) }; end
39
+ def headers ; super.merge('location' => url) ; end
40
+ def body ; [] ; end
34
41
  end
42
+ class Moved < Found ; def status; 301; end; end
35
43
 
36
44
  # -----------------------------------------------------------------
37
45
 
@@ -55,14 +63,14 @@ module Jellyfish
55
63
  raise
56
64
  end
57
65
 
58
- def log message; jellyfish.log( message, env['rack.errors']); end
59
- def log_error error; jellyfish.log_error(error, env['rack.errors']); end
66
+ def log message; jellyfish.log( message, env); end
67
+ def log_error error; jellyfish.log_error(error, env); end
60
68
  def request ; @request ||= Rack::Request.new(env); end
61
69
  def halt *args; throw(:halt, *args) ; end
62
70
  def cascade ; halt(Jellyfish::Cascade) ; end
63
71
  def not_found ; halt(Jellyfish::NotFound.new) ; end
64
72
  def found url; halt(Jellyfish:: Found.new(url)); end
65
- alias_method :redirect, :found
73
+ def moved url; halt(Jellyfish:: Moved.new(url)); end
66
74
 
67
75
  def path_info ; env['PATH_INFO'] || '/' ; end
68
76
  def request_method; env['REQUEST_METHOD'] || 'GET'; end
@@ -190,7 +198,7 @@ module Jellyfish
190
198
  when Cascade
191
199
  cascade(ctrl, env)
192
200
  when Response
193
- handle(ctrl, res, env['rack.errors'])
201
+ handle(ctrl, res, env)
194
202
  when Array
195
203
  res
196
204
  when NilClass # make sure we return rack triple
@@ -199,47 +207,48 @@ module Jellyfish
199
207
  raise TypeError.new("Expect the response to be a Jellyfish::Response" \
200
208
  " or Rack triple (Array), but got: #{res.inspect}")
201
209
  end
202
- rescue => e
203
- handle(ctrl, e, env['rack.errors'])
210
+ rescue => error
211
+ handle(ctrl, error, env)
204
212
  end
205
213
 
206
- def log_error e, stderr
207
- return unless stderr
208
- stderr.puts("[#{self.class.name}] #{e.inspect} #{e.backtrace}")
214
+ def log_error error, env
215
+ env['rack.errors']&.
216
+ puts("[#{self.class.name}] #{error.inspect}" \
217
+ " for #{env['PATH_INFO'] || '/'} #{error.backtrace}")
209
218
  end
210
219
 
211
- def log msg, stderr
212
- return unless stderr
213
- stderr.puts("[#{self.class.name}] #{msg}")
220
+ def log msg, env
221
+ env['rack.errors']&.
222
+ puts("[#{self.class.name}] #{msg}")
214
223
  end
215
224
 
216
225
  private
217
226
  def cascade ctrl, env
218
227
  app.call(env)
219
- rescue => e
220
- handle(ctrl, e, env['rack.errors'])
228
+ rescue => error
229
+ handle(ctrl, error, env)
221
230
  end
222
231
 
223
- def handle ctrl, e, stderr=nil
224
- if handler = best_handler(e)
225
- ctrl.block_call(e, handler)
232
+ def handle ctrl, error, env
233
+ if handler = best_handler(error)
234
+ ctrl.block_call(error, handler)
226
235
  elsif !self.class.handle_exceptions
227
- raise e
228
- elsif e.kind_of?(Response) # InternalError ends up here if no handlers
229
- [e.status, e.headers, e.body]
236
+ raise error
237
+ elsif error.kind_of?(Response) # InternalError ends up here if no handlers
238
+ [error.status, error.headers, error.body]
230
239
  else # fallback and see if there's any InternalError handler
231
- log_error(e, stderr)
232
- handle(ctrl, InternalError.new)
240
+ log_error(error, env)
241
+ handle(ctrl, InternalError.new, env)
233
242
  end
234
243
  end
235
244
 
236
- def best_handler e
245
+ def best_handler error
237
246
  handlers = self.class.handlers
238
- if handlers.key?(e.class)
239
- handlers[e.class]
247
+ if handlers.key?(error.class)
248
+ handlers[error.class]
240
249
  else # or find the nearest match and cache it
241
- ancestors = e.class.ancestors
242
- handlers[e.class] = handlers.dup. # thread safe iteration
250
+ ancestors = error.class.ancestors
251
+ handlers[error.class] = handlers.dup. # thread safe iteration
243
252
  inject([nil, Float::INFINITY]){ |(handler, val), (klass, block)|
244
253
  idx = ancestors.index(klass) || Float::INFINITY # lower is better
245
254
  if idx < val then [block, idx] else [handler, val] end }.first
data/task/README.md CHANGED
@@ -13,11 +13,11 @@ Provided tasks:
13
13
 
14
14
  ## REQUIREMENTS:
15
15
 
16
- * Tested with MRI (official CRuby), Rubinius and JRuby.
16
+ * Tested with MRI (official CRuby) and JRuby.
17
17
 
18
18
  ## INSTALLATION:
19
19
 
20
- git submodule add git://github.com/godfat/gemgem.git task
20
+ git submodule add https://github.com/godfat/gemgem.git task
21
21
 
22
22
  And in Rakefile:
23
23
 
@@ -39,13 +39,13 @@ end
39
39
 
40
40
  Apache License 2.0 (Apache-2.0)
41
41
 
42
- Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
42
+ Copyright (c) 2011-2023, Lin Jen-Shin (godfat)
43
43
 
44
44
  Licensed under the Apache License, Version 2.0 (the "License");
45
45
  you may not use this file except in compliance with the License.
46
46
  You may obtain a copy of the License at
47
47
 
48
- <http://www.apache.org/licenses/LICENSE-2.0>
48
+ <https://www.apache.org/licenses/LICENSE-2.0>
49
49
 
50
50
  Unless required by applicable law or agreed to in writing, software
51
51
  distributed under the License is distributed on an "AS IS" BASIS,
data/task/gemgem.rb CHANGED
@@ -42,6 +42,7 @@ module Gemgem
42
42
 
43
43
  def gem_install
44
44
  require 'rubygems/commands/install_command'
45
+ require 'rubygems/package'
45
46
  # read ~/.gemrc
46
47
  Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
47
48
  Gem::Command.extra_args = Gem.configuration[:gem]
@@ -51,7 +52,8 @@ module Gemgem
51
52
  cmd.handle_options([])
52
53
 
53
54
  # install
54
- install = Gem::Installer.new(gem_path, cmd.options)
55
+ gem_package = Gem::Package.new(gem_path)
56
+ install = Gem::Installer.new(gem_package, cmd.options)
55
57
  install.install
56
58
  puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
57
59
  end
@@ -28,10 +28,10 @@ describe Jellyfish::Builder do
28
28
  would "supports mapping" do
29
29
  app = builder_to_app do
30
30
  map '/' do |outer_env|
31
- run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['root']] }
31
+ run lambda { |inner_env| [200, {"content-type" => "text/plain"}, ['root']] }
32
32
  end
33
33
  map '/sub' do
34
- run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['sub']] }
34
+ run lambda { |inner_env| [200, {"content-type" => "text/plain"}, ['sub']] }
35
35
  end
36
36
  end
37
37
  Rack::MockRequest.new(app).get("/").body.to_s.should.eq 'root'
@@ -56,7 +56,7 @@ describe Jellyfish::Builder do
56
56
  'secret' == password
57
57
  end
58
58
 
59
- run lambda { |env| [200, {"Content-Type" => "text/plain"}, ['Hi Boss']] }
59
+ run lambda { |env| [200, {"content-type" => "text/plain"}, ['Hi Boss']] }
60
60
  end
61
61
 
62
62
  response = Rack::MockRequest.new(app).get("/")
@@ -84,9 +84,9 @@ describe Jellyfish::Builder do
84
84
  would "can mix map and run for endpoints" do
85
85
  app = builder_to_app do
86
86
  map '/sub' do
87
- run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['sub']] }
87
+ run lambda { |inner_env| [200, {"content-type" => "text/plain"}, ['sub']] }
88
88
  end
89
- run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['root']] }
89
+ run lambda { |inner_env| [200, {"content-type" => "text/plain"}, ['root']] }
90
90
  end
91
91
 
92
92
  Rack::MockRequest.new(app).get("/").body.to_s.should.eq 'root'
@@ -123,7 +123,7 @@ describe Jellyfish::Builder do
123
123
  def call(env)
124
124
  raise "bzzzt" if @called > 0
125
125
  @called += 1
126
- [200, {'Content-Type' => 'text/plain'}, ['OK']]
126
+ [200, {'content-type' => 'text/plain'}, ['OK']]
127
127
  end
128
128
  end
129
129
 
@@ -8,9 +8,9 @@ describe Jellyfish::URLMap do
8
8
  would "dispatches paths correctly" do
9
9
  app = lambda { |env|
10
10
  [200, {
11
- 'X-ScriptName' => env['SCRIPT_NAME'],
12
- 'X-PathInfo' => env['PATH_INFO'],
13
- 'Content-Type' => 'text/plain'
11
+ 'x-scriptname' => env['SCRIPT_NAME'],
12
+ 'x-pathinfo' => env['PATH_INFO'],
13
+ 'content-type' => 'text/plain'
14
14
  }, [""]]
15
15
  }
16
16
  map = Rack::Lint.new(Jellyfish::URLMap.new({
@@ -27,102 +27,102 @@ describe Jellyfish::URLMap do
27
27
 
28
28
  res = Rack::MockRequest.new(map).get("/foo")
29
29
  res.should.ok?
30
- res["X-ScriptName"].should.eq "/foo"
31
- res["X-PathInfo"].should.eq ""
30
+ res["x-scriptname"].should.eq "/foo"
31
+ res["x-pathinfo"].should.eq ""
32
32
 
33
33
  res = Rack::MockRequest.new(map).get("/foo/")
34
34
  res.should.ok?
35
- res["X-ScriptName"].should.eq "/foo"
36
- res["X-PathInfo"].should.eq "/"
35
+ res["x-scriptname"].should.eq "/foo"
36
+ res["x-pathinfo"].should.eq "/"
37
37
 
38
38
  res = Rack::MockRequest.new(map).get("/foo/bar")
39
39
  res.should.ok?
40
- res["X-ScriptName"].should.eq "/foo/bar"
41
- res["X-PathInfo"].should.eq ""
40
+ res["x-scriptname"].should.eq "/foo/bar"
41
+ res["x-pathinfo"].should.eq ""
42
42
 
43
43
  res = Rack::MockRequest.new(map).get("/foo/bar/")
44
44
  res.should.ok?
45
- res["X-ScriptName"].should.eq "/foo/bar"
46
- res["X-PathInfo"].should.eq "/"
45
+ res["x-scriptname"].should.eq "/foo/bar"
46
+ res["x-pathinfo"].should.eq "/"
47
47
 
48
48
  res = Rack::MockRequest.new(map).get("/foo///bar//quux")
49
49
  res.status.should.eq 200
50
50
  res.should.ok?
51
- res["X-ScriptName"].should.eq "/foo/bar"
52
- res["X-PathInfo"].should.eq "//quux"
51
+ res["x-scriptname"].should.eq "/foo/bar"
52
+ res["x-pathinfo"].should.eq "//quux"
53
53
 
54
54
  res = Rack::MockRequest.new(map).get("/foo/quux", "SCRIPT_NAME" => "/bleh")
55
55
  res.should.ok?
56
- res["X-ScriptName"].should.eq "/bleh/foo"
57
- res["X-PathInfo"].should.eq "/quux"
56
+ res["x-scriptname"].should.eq "/bleh/foo"
57
+ res["x-pathinfo"].should.eq "/quux"
58
58
 
59
59
  res = Rack::MockRequest.new(map).get("/bar", 'HTTP_HOST' => 'foo.org')
60
60
  res.should.ok?
61
- res["X-ScriptName"].should.eq "/bar"
62
- res["X-PathInfo"].should.empty?
61
+ res["x-scriptname"].should.eq "/bar"
62
+ res["x-pathinfo"].should.empty?
63
63
 
64
64
  res = Rack::MockRequest.new(map).get("/bar/", 'HTTP_HOST' => 'foo.org')
65
65
  res.should.ok?
66
- res["X-ScriptName"].should.eq "/bar"
67
- res["X-PathInfo"].should.eq '/'
66
+ res["x-scriptname"].should.eq "/bar"
67
+ res["x-pathinfo"].should.eq '/'
68
68
  end
69
69
 
70
70
  would "dispatches hosts correctly" do
71
71
  map = Rack::Lint.new(Jellyfish::URLMap.new("http://foo.org/" => lambda { |env|
72
72
  [200,
73
- { "Content-Type" => "text/plain",
74
- "X-Position" => "foo.org",
75
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
73
+ { "content-type" => "text/plain",
74
+ "x-position" => "foo.org",
75
+ "x-host" => env["HTTP_HOST"] || env["SERVER_NAME"],
76
76
  }, [""]]},
77
77
  "http://subdomain.foo.org/" => lambda { |env|
78
78
  [200,
79
- { "Content-Type" => "text/plain",
80
- "X-Position" => "subdomain.foo.org",
81
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
79
+ { "content-type" => "text/plain",
80
+ "x-position" => "subdomain.foo.org",
81
+ "x-host" => env["HTTP_HOST"] || env["SERVER_NAME"],
82
82
  }, [""]]},
83
83
  "http://bar.org/" => lambda { |env|
84
84
  [200,
85
- { "Content-Type" => "text/plain",
86
- "X-Position" => "bar.org",
87
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
85
+ { "content-type" => "text/plain",
86
+ "x-position" => "bar.org",
87
+ "x-host" => env["HTTP_HOST"] || env["SERVER_NAME"],
88
88
  }, [""]]},
89
89
  "/" => lambda { |env|
90
90
  [200,
91
- { "Content-Type" => "text/plain",
92
- "X-Position" => "default.org",
93
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
91
+ { "content-type" => "text/plain",
92
+ "x-position" => "default.org",
93
+ "x-host" => env["HTTP_HOST"] || env["SERVER_NAME"],
94
94
  }, [""]]}
95
95
  ))
96
96
 
97
97
  res = Rack::MockRequest.new(map).get("/")
98
98
  res.should.ok?
99
- res["X-Position"].should.eq "default.org"
99
+ res["x-position"].should.eq "default.org"
100
100
 
101
101
  res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "bar.org")
102
102
  res.should.ok?
103
- res["X-Position"].should.eq "bar.org"
103
+ res["x-position"].should.eq "bar.org"
104
104
 
105
105
  res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "foo.org")
106
106
  res.should.ok?
107
- res["X-Position"].should.eq "foo.org"
107
+ res["x-position"].should.eq "foo.org"
108
108
 
109
109
  res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "subdomain.foo.org", "SERVER_NAME" => "foo.org")
110
110
  res.should.ok?
111
- res["X-Position"].should.eq "subdomain.foo.org"
111
+ res["x-position"].should.eq "subdomain.foo.org"
112
112
 
113
113
  res = Rack::MockRequest.new(map).get("http://foo.org/")
114
114
  res.should.ok?
115
- res["X-Position"].should.eq "foo.org"
115
+ res["x-position"].should.eq "foo.org"
116
116
 
117
117
  res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "example.org")
118
118
  res.should.ok?
119
- res["X-Position"].should.eq "default.org"
119
+ res["x-position"].should.eq "default.org"
120
120
 
121
121
  res = Rack::MockRequest.new(map).get("/",
122
122
  "HTTP_HOST" => "example.org:9292",
123
123
  "SERVER_PORT" => "9292")
124
124
  res.should.ok?
125
- res["X-Position"].should.eq "default.org"
125
+ res["x-position"].should.eq "default.org"
126
126
  end
127
127
 
128
128
  would "be nestable" do
@@ -130,10 +130,10 @@ describe Jellyfish::URLMap do
130
130
  Jellyfish::URLMap.new("/bar" =>
131
131
  Jellyfish::URLMap.new("/quux" => lambda { |env|
132
132
  [200,
133
- { "Content-Type" => "text/plain",
134
- "X-Position" => "/foo/bar/quux",
135
- "X-PathInfo" => env["PATH_INFO"],
136
- "X-ScriptName" => env["SCRIPT_NAME"],
133
+ { "content-type" => "text/plain",
134
+ "x-position" => "/foo/bar/quux",
135
+ "x-pathinfo" => env["PATH_INFO"],
136
+ "x-scriptname" => env["SCRIPT_NAME"],
137
137
  }, [""]]}
138
138
  ))))
139
139
 
@@ -142,97 +142,97 @@ describe Jellyfish::URLMap do
142
142
 
143
143
  res = Rack::MockRequest.new(map).get("/foo/bar/quux")
144
144
  res.should.ok?
145
- res["X-Position"].should.eq "/foo/bar/quux"
146
- res["X-PathInfo"].should.eq ""
147
- res["X-ScriptName"].should.eq "/foo/bar/quux"
145
+ res["x-position"].should.eq "/foo/bar/quux"
146
+ res["x-pathinfo"].should.eq ""
147
+ res["x-scriptname"].should.eq "/foo/bar/quux"
148
148
  end
149
149
 
150
150
  would "route root apps correctly" do
151
151
  map = Rack::Lint.new(Jellyfish::URLMap.new("/" => lambda { |env|
152
152
  [200,
153
- { "Content-Type" => "text/plain",
154
- "X-Position" => "root",
155
- "X-PathInfo" => env["PATH_INFO"],
156
- "X-ScriptName" => env["SCRIPT_NAME"]
153
+ { "content-type" => "text/plain",
154
+ "x-position" => "root",
155
+ "x-pathinfo" => env["PATH_INFO"],
156
+ "x-scriptname" => env["SCRIPT_NAME"]
157
157
  }, [""]]},
158
158
  "/foo" => lambda { |env|
159
159
  [200,
160
- { "Content-Type" => "text/plain",
161
- "X-Position" => "foo",
162
- "X-PathInfo" => env["PATH_INFO"],
163
- "X-ScriptName" => env["SCRIPT_NAME"]
160
+ { "content-type" => "text/plain",
161
+ "x-position" => "foo",
162
+ "x-pathinfo" => env["PATH_INFO"],
163
+ "x-scriptname" => env["SCRIPT_NAME"]
164
164
  }, [""]]}
165
165
  ))
166
166
 
167
167
  res = Rack::MockRequest.new(map).get("/foo/bar")
168
168
  res.should.ok?
169
- res["X-Position"].should.eq "foo"
170
- res["X-PathInfo"].should.eq "/bar"
171
- res["X-ScriptName"].should.eq "/foo"
169
+ res["x-position"].should.eq "foo"
170
+ res["x-pathinfo"].should.eq "/bar"
171
+ res["x-scriptname"].should.eq "/foo"
172
172
 
173
173
  res = Rack::MockRequest.new(map).get("/foo")
174
174
  res.should.ok?
175
- res["X-Position"].should.eq "foo"
176
- res["X-PathInfo"].should.eq ""
177
- res["X-ScriptName"].should.eq "/foo"
175
+ res["x-position"].should.eq "foo"
176
+ res["x-pathinfo"].should.eq ""
177
+ res["x-scriptname"].should.eq "/foo"
178
178
 
179
179
  res = Rack::MockRequest.new(map).get("/bar")
180
180
  res.should.ok?
181
- res["X-Position"].should.eq "root"
182
- res["X-PathInfo"].should.eq "/bar"
183
- res["X-ScriptName"].should.eq ""
181
+ res["x-position"].should.eq "root"
182
+ res["x-pathinfo"].should.eq "/bar"
183
+ res["x-scriptname"].should.eq ""
184
184
 
185
185
  res = Rack::MockRequest.new(map).get("")
186
186
  res.should.ok?
187
- res["X-Position"].should.eq "root"
188
- res["X-PathInfo"].should.eq "/"
189
- res["X-ScriptName"].should.eq ""
187
+ res["x-position"].should.eq "root"
188
+ res["x-pathinfo"].should.eq "/"
189
+ res["x-scriptname"].should.eq ""
190
190
  end
191
191
 
192
192
  would "not squeeze slashes" do
193
193
  map = Rack::Lint.new(Jellyfish::URLMap.new("/" => lambda { |env|
194
194
  [200,
195
- { "Content-Type" => "text/plain",
196
- "X-Position" => "root",
197
- "X-PathInfo" => env["PATH_INFO"],
198
- "X-ScriptName" => env["SCRIPT_NAME"]
195
+ { "content-type" => "text/plain",
196
+ "x-position" => "root",
197
+ "x-pathinfo" => env["PATH_INFO"],
198
+ "x-scriptname" => env["SCRIPT_NAME"]
199
199
  }, [""]]},
200
200
  "/foo" => lambda { |env|
201
201
  [200,
202
- { "Content-Type" => "text/plain",
203
- "X-Position" => "foo",
204
- "X-PathInfo" => env["PATH_INFO"],
205
- "X-ScriptName" => env["SCRIPT_NAME"]
202
+ { "content-type" => "text/plain",
203
+ "x-position" => "foo",
204
+ "x-pathinfo" => env["PATH_INFO"],
205
+ "x-scriptname" => env["SCRIPT_NAME"]
206
206
  }, [""]]}
207
207
  ))
208
208
 
209
209
  res = Rack::MockRequest.new(map).get("/http://example.org/bar")
210
210
  res.should.ok?
211
- res["X-Position"].should.eq "root"
212
- res["X-PathInfo"].should.eq "/http://example.org/bar"
213
- res["X-ScriptName"].should.eq ""
211
+ res["x-position"].should.eq "root"
212
+ res["x-pathinfo"].should.eq "/http://example.org/bar"
213
+ res["x-scriptname"].should.eq ""
214
214
  end
215
215
 
216
216
  would "not be case sensitive with hosts" do
217
217
  map = Rack::Lint.new(Jellyfish::URLMap.new("http://example.org/" => lambda { |env|
218
218
  [200,
219
- { "Content-Type" => "text/plain",
220
- "X-Position" => "root",
221
- "X-PathInfo" => env["PATH_INFO"],
222
- "X-ScriptName" => env["SCRIPT_NAME"]
219
+ { "content-type" => "text/plain",
220
+ "x-position" => "root",
221
+ "x-pathinfo" => env["PATH_INFO"],
222
+ "x-scriptname" => env["SCRIPT_NAME"]
223
223
  }, [""]]}
224
224
  ))
225
225
 
226
226
  res = Rack::MockRequest.new(map).get("http://example.org/")
227
227
  res.should.ok?
228
- res["X-Position"].should.eq "root"
229
- res["X-PathInfo"].should.eq "/"
230
- res["X-ScriptName"].should.eq ""
228
+ res["x-position"].should.eq "root"
229
+ res["x-pathinfo"].should.eq "/"
230
+ res["x-scriptname"].should.eq ""
231
231
 
232
232
  res = Rack::MockRequest.new(map).get("http://EXAMPLE.ORG/")
233
233
  res.should.ok?
234
- res["X-Position"].should.eq "root"
235
- res["X-PathInfo"].should.eq "/"
236
- res["X-ScriptName"].should.eq ""
234
+ res["x-position"].should.eq "root"
235
+ res["x-pathinfo"].should.eq "/"
236
+ res["x-scriptname"].should.eq ""
237
237
  end
238
238
  end
@@ -38,7 +38,7 @@ describe 'Sinatra base_test.rb' do
38
38
 
39
39
  describe 'Jellyfish as a Rack middleware' do
40
40
  inner_app ||= lambda{ |env|
41
- [210, {'X-Downstream' => 'true'}, ['Hello from downstream']]
41
+ [210, {'x-downstream' => 'true'}, ['Hello from downstream']]
42
42
  }
43
43
 
44
44
  app = Class.new{
@@ -55,7 +55,7 @@ describe 'Sinatra base_test.rb' do
55
55
  end
56
56
 
57
57
  get '/explicit-forward' do
58
- headers_merge 'X-Middleware' => 'true'
58
+ headers_merge 'x-middleware' => 'true'
59
59
  status, headers, _ = jellyfish.app.call(env)
60
60
  self.status status
61
61
  self.headers headers
@@ -80,14 +80,14 @@ describe 'Sinatra base_test.rb' do
80
80
  would 'forward requests downstream when no matching route found' do
81
81
  status, headers, body = get('/missing', app)
82
82
  status .should.eq 210
83
- headers['X-Downstream'].should.eq 'true'
83
+ headers['x-downstream'].should.eq 'true'
84
84
  body .should.eq ['Hello from downstream']
85
85
  end
86
86
 
87
87
  would 'call the downstream app directly and return result' do
88
88
  status, headers, body = get('/low-level-forward', app)
89
89
  status .should.eq 210
90
- headers['X-Downstream'].should.eq 'true'
90
+ headers['x-downstream'].should.eq 'true'
91
91
  body .should.eq ['Hello from downstream']
92
92
  end
93
93
 
@@ -96,8 +96,8 @@ describe 'Sinatra base_test.rb' do
96
96
  get('/explicit-forward', Rack::ContentLength.new(app))
97
97
 
98
98
  status .should.eq 210
99
- headers['X-Downstream'] .should.eq 'true'
100
- headers['Content-Length'].should.eq '28'
99
+ headers['x-downstream'] .should.eq 'true'
100
+ headers['content-length'].should.eq '28'
101
101
  body.to_a .should.eq ['Hello after explicit forward']
102
102
  end
103
103
  end
@@ -70,7 +70,7 @@ describe 'Sinatra routing_test.rb' do
70
70
  app = Class.new{
71
71
  include Jellyfish
72
72
  get{
73
- self.headers 'Content-Type' => 'text/plain'
73
+ self.headers 'content-type' => 'text/plain'
74
74
  status, headers, body = jellyfish.app.call(env)
75
75
  self.status status
76
76
  self.body body
@@ -79,7 +79,7 @@ describe 'Sinatra routing_test.rb' do
79
79
  }.new(Class.new{
80
80
  include Jellyfish
81
81
  handle Jellyfish::NotFound do
82
- headers_merge 'Content-Type' => 'text/html'
82
+ headers_merge 'content-type' => 'text/html'
83
83
  status 404
84
84
  '<h1>Not Found</h1>'
85
85
  end
@@ -87,7 +87,7 @@ describe 'Sinatra routing_test.rb' do
87
87
 
88
88
  status, headers, body = get('/foo', app)
89
89
  status .should.eq 404
90
- headers['Content-Type'].should.eq 'text/html'
90
+ headers['content-type'].should.eq 'text/html'
91
91
  body .should.eq ['<h1>Not Found</h1>']
92
92
  end
93
93
 
@@ -30,7 +30,7 @@ describe 'from README.md' do
30
30
  sock = nil
31
31
  status, headers, body = File.open(File::NULL) do |input|
32
32
  app.call(
33
- 'HTTP_VERSION' => 'HTTP/1.1',
33
+ 'SERVER_PROTOCOL'=> 'HTTP/1.1',
34
34
  'REQUEST_METHOD' => method,
35
35
  'HTTP_HOST' => host,
36
36
  'PATH_INFO' => pinfo,