Skip to content

Commit 4e3e812

Browse files
authored
Merge pull request #1137 from tdiary/try-rack3-again
Try rack3 again
2 parents 2236fdd + cd7401d commit 4e3e812

File tree

11 files changed

+52
-38
lines changed

11 files changed

+52
-38
lines changed

Diff for: Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source 'https://rubygems.org'
22

3-
gem 'rack', '< 3'
3+
gem 'rack'
4+
gem 'rackup'
45
gem 'hikidoc'
56
gem 'fastimage'
67
gem 'emot'

Diff for: Gemfile.lock

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ GEM
7474
power_assert (2.0.3)
7575
public_suffix (5.0.4)
7676
racc (1.7.3)
77-
rack (2.2.8.1)
77+
rack (3.0.9.1)
7878
rack-test (2.1.0)
7979
rack (>= 1.3)
8080
racksh (1.0.1)
8181
rack (>= 1.0)
8282
rack-test (>= 0.5)
83+
rackup (2.1.0)
84+
rack (>= 3)
85+
webrick (~> 1.8)
8386
rake (13.1.0)
8487
redcarpet (3.6.0)
8588
regexp_parser (2.9.0)
@@ -147,8 +150,9 @@ DEPENDENCIES
147150
mime-types
148151
octokit
149152
pit
150-
rack (< 3)
153+
rack
151154
racksh
155+
rackup
152156
rake
153157
redcarpet
154158
rexml

Diff for: lib/aws/pa_api.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_items(asin, locale)
5353
"X-Amz-Date" => time_stamp,
5454
"X-Amz-Content-Sha256" => OpenSSL::Digest::SHA256.hexdigest(payload),
5555
"Authorization" => authorization,
56-
"Content-Type" => "application/json; charset=utf-8"
56+
"content-type" => "application/json; charset=utf-8"
5757
}
5858
uri = URI("https://#{MARKETS[locale].host}/paapi5/getitems")
5959
http = Net::HTTP.new(uri.host, uri.port)

Diff for: lib/tdiary/application.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def call( env )
5353
rescue Exception => e
5454
body = ["#{e.class}: #{e}\n"]
5555
body << e.backtrace.join("\n")
56-
[500, {'Content-Type' => 'text/plain'}, body]
56+
[500, {'content-type' => 'text/plain'}, body]
5757
end
5858
end
5959

Diff for: lib/tdiary/dispatcher.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class << self
3131
# stolen from Rack::Handler::CGI.send_headers
3232
def send_headers(status, headers)
3333
begin
34-
headers['type'] = headers.delete('Content-Type')
34+
headers['type'] = headers.delete('content-type')
3535
$stdout.print CGI.new.header({'Status'=>status}.merge(headers))
3636
rescue EOFError
3737
charset = headers.delete('charset')
38-
headers['Content-Type'] ||= headers.delete( 'type' )
39-
headers['Content-Type'] += "; charset=#{charset}" if charset
38+
headers['content-type'] ||= headers.delete( 'type' )
39+
headers['content-type'] += "; charset=#{charset}" if charset
4040
$stdout.print headers.map{|k,v| "#{k}: #{v}\r\n"}.join << "\r\n"
4141
end
4242
$stdout.flush
@@ -71,7 +71,12 @@ def adopt_rack_request_to_plain_old_tdiary_style( env )
7171
req = TDiary::Request.new( env )
7272
req.params # fill params to tdiary_request
7373
$RACK_ENV = req.env
74-
env["rack.input"].rewind
74+
# Rack 3.x has been removed rack.input rewinding
75+
begin
76+
env["rack.input"].instance_variable_get(:@input).rewind
77+
rescue
78+
env["rack.input"].rewind
79+
end
7580
fake_stdin_as_params
7681
req
7782
end

Diff for: lib/tdiary/dispatcher/index_main.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,43 @@ def run
2121

2222
begin
2323
head = {
24-
'Content-Type' => 'text/html; charset=UTF-8',
25-
'Vary' => 'User-Agent'
24+
'content-type' => 'text/html; charset=UTF-8',
25+
'vary' => 'User-Agent'
2626
}
2727
head['status'] = status if status
2828
body = ''
2929
head['Last-Modified'] = CGI::rfc1123_date( tdiary.last_modified )
3030

3131
if request.head?
32-
head['Pragma'] = 'no-cache'
33-
head['Cache-Control'] = 'no-cache'
32+
head['pragma'] = 'no-cache'
33+
head['cache-control'] = 'no-cache'
3434
return TDiary::Response.new( '', 200, head )
3535
else
3636
require 'openssl'
3737
body = tdiary.eval_rhtml
38-
head['ETag'] = %Q["#{OpenSSL::Digest::SHA256.hexdigest( body )}"]
39-
if ENV['HTTP_IF_NONE_MATCH'] == head['ETag'] and request.get? then
38+
head['etag'] = %Q["#{OpenSSL::Digest::SHA256.hexdigest( body )}"]
39+
if ENV['HTTP_IF_NONE_MATCH'] == head['etag'] and request.get? then
4040
head['status'] = CGI::HTTP_STATUS['NOT_MODIFIED']
4141
else
4242
head['charset'] = conf.encoding
43-
head['Content-Length'] = body.bytesize.to_s
43+
head['content-length'] = body.bytesize.to_s
4444
end
45-
head['Pragma'] = 'no-cache'
46-
head['Cache-Control'] = 'no-cache'
47-
head['X-Frame-Options'] = conf.x_frame_options if conf.x_frame_options
45+
head['pragma'] = 'no-cache'
46+
head['cache-control'] = 'no-cache'
47+
head['x-frame-options'] = conf.x_frame_options if conf.x_frame_options
4848
head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
4949
TDiary::Response.new( body, ::TDiary::Dispatcher.extract_status_for_legacy_tdiary( head ), head )
5050
end
5151
rescue TDiary::NotFound
5252
body = %Q[
5353
<h1>404 Not Found</h1>
5454
<div>#{' ' * 500}</div>]
55-
TDiary::Response.new( body, 404, { 'Content-Type' => 'text/html' } )
55+
TDiary::Response.new( body, 404, { 'content-type' => 'text/html' } )
5656
end
5757
rescue TDiary::ForceRedirect
5858
head = {
5959
#'Location' => $!.path
60-
'Content-Type' => 'text/html',
60+
'content-type' => 'text/html',
6161
}
6262
body = %Q[
6363
<html>

Diff for: lib/tdiary/dispatcher/update_main.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ def run
2020
head = {}; body = ''
2121
body = tdiary.eval_rhtml
2222
head = {
23-
'Content-Type' => 'text/html; charset=UTF-8',
23+
'content-type' => 'text/html; charset=UTF-8',
2424
'charset' => conf.encoding,
25-
'Content-Length' => body.bytesize.to_s,
26-
'Vary' => 'User-Agent',
27-
'X-Frame-Options' => 'SAMEORIGIN'
25+
'content-length' => body.bytesize.to_s,
26+
'vary' => 'User-Agent',
27+
'x-frame-options' => 'SAMEORIGIN'
2828
}
2929
body = ( request.head? ? '' : body )
3030
TDiary::Response.new( body, 200, head )
3131
rescue TDiary::ForceRedirect
3232
head = {
3333
#'Location' => $!.path
34-
'Content-Type' => 'text/html',
34+
'content-type' => 'text/html',
3535
}
3636
body = %Q[
3737
<html>

Diff for: lib/tdiary/rack/auth/basic.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def call(env)
2222
begin
2323
@authenticator.call(env)
2424
rescue PasswordFileNotFound => e
25-
[403, {"Content-Type" => "text/plain"}, [e.message]]
25+
[403, {"content-type" => "text/plain"}, [e.message]]
2626
end
2727
end
2828
end

Diff for: lib/tdiary/rack/auth/omniauth/authorization.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ def login(env)
3232
req = ::Rack::Request.new(env)
3333
env['rack.session']['tdiary.auth.redirect'] = "#{req.base_url}#{req.fullpath}"
3434
redirect = File.join("#{req.base_url}#{req.path}", "#{::OmniAuth.config.path_prefix}/#{@provider}")
35-
[302, {'Content-Type' => 'text/plain', 'Location' => redirect}, []]
35+
[302, {'content-type' => 'text/plain', 'location' => redirect}, []]
3636
end
3737

3838
def logout(env)
3939
env['rack.session']['user_id'] = nil
4040
end
4141

4242
def forbidden
43-
[403, {'Content-Type' => 'text/plain'}, ['forbidden']]
43+
[403, {'content-type' => 'text/plain'}, ['forbidden']]
4444
end
4545

4646
def callback(env)
@@ -51,7 +51,7 @@ def callback(env)
5151
env['rack.session']['auth'] = auth
5252
env['REMOTE_USER'] = "#{auth.uid}@#{auth.provider}"
5353
redirect = env['rack.session']['tdiary.auth.redirect'] || '/'
54-
[302, {'Content-Type' => 'text/plain', 'Location' => redirect}, []]
54+
[302, {'content-type' => 'text/plain', 'location' => redirect}, []]
5555
end
5656

5757
def authenticate?(env)

Diff for: lib/tdiary/rack/valid_request_path.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def call( env )
1717

1818
body = "Not Found: #{env['PATH_INFO']}"
1919
if env["REQUEST_METHOD"] == "HEAD"
20-
[404, {'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s}, []]
20+
[404, {'content-type' => 'text/plain', 'content-length' => body.length.to_s}, []]
2121
else
22-
[404, {'Content-Type' => 'text/plain'}, [body]]
22+
[404, {'content-type' => 'text/plain'}, [body]]
2323
end
2424
end
2525
end

Diff for: misc/paas/heroku/Gemfile.lock

+10-6
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,20 @@ GEM
143143
faraday (>= 0.13.0, < 1.0)
144144
mime-types
145145
racc (1.7.3)
146-
rack (2.2.8.1)
147-
rack-protection (3.2.0)
146+
rack (3.0.9.1)
147+
rack-protection (4.0.0)
148148
base64 (>= 0.1.0)
149-
rack (~> 2.2, >= 2.2.4)
150-
rack-session (1.0.2)
151-
rack (< 3)
149+
rack (>= 3.0.0, < 4)
150+
rack-session (2.0.0)
151+
rack (>= 3.0.0)
152152
rack-test (2.1.0)
153153
rack (>= 1.3)
154154
racksh (1.0.1)
155155
rack (>= 1.0)
156156
rack-test (>= 0.5)
157+
rackup (2.1.0)
158+
rack (>= 3)
159+
webrick (~> 1.8)
157160
rake (13.1.0)
158161
rdtool (0.6.38)
159162
redcarpet (3.6.0)
@@ -258,9 +261,10 @@ DEPENDENCIES
258261
omniauth-github
259262
pit
260263
puma
261-
rack (< 3)
264+
rack
262265
rack-session
263266
racksh
267+
rackup
264268
rake
265269
redcarpet
266270
rexml

0 commit comments

Comments
 (0)