Skip to content

Commit 197853f

Browse files
committed
Remove old Rack 1.x / Rails < 3 compatibility code
We are only supporting Rack 2.x onwards now anyway.
1 parent 94c5383 commit 197853f

File tree

6 files changed

+11
-63
lines changed

6 files changed

+11
-63
lines changed

src/main/java/org/jruby/rack/servlet/ResponseCapture.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public boolean isHandled(final HttpServletRequest request) {
231231

232232
// consider HTTP OPTIONS with "Allow" header unhandled :
233233
if ( request != null && "OPTIONS".equals( request.getMethod() ) ) {
234-
final Collection<String> headerNames = getHeaderNamesOrNull();
234+
final Collection<String> headerNames = getHeaderNames();
235235
if ( headerNames == null || headerNames.isEmpty() ) {
236236
// not to happen but there's all kind of beasts out there
237237
return false;
@@ -277,17 +277,4 @@ public void setHandledByDefault(boolean handledByDefault) {
277277
public boolean isOutputAccessed() {
278278
return output != null;
279279
}
280-
281-
@SuppressWarnings("unchecked")
282-
private Collection<String> getHeaderNamesOrNull() {
283-
// NOTE: getHeaderNames since Servlet API 3.0 JRuby-Rack 1.1 still supports 2.5
284-
try {
285-
final Method getHeaderNames = getResponse().getClass().getMethod("getHeaderNames");
286-
return (Collection<String>) getHeaderNames.invoke( getResponse() );
287-
}
288-
catch (NoSuchMethodException e) { return null; }
289-
catch (IllegalAccessException e) { return null; }
290-
catch (InvocationTargetException e) { return null; }
291-
}
292-
293280
}

src/main/ruby/jruby/rack/chunked.rb

-12
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,4 @@ def each(&block)
2020
@body.each(&block) # no-chunking on servlets
2121
end
2222

23-
end if defined? Rack::Chunked::Body
24-
25-
unless defined? Rack::Chunked::Body # Rack 1.1
26-
27-
Rack::Chunked.class_eval do
28-
29-
def each(&block)
30-
@body.each(&block) # no-chunking on servlets
31-
end
32-
33-
end
34-
3523
end

src/main/ruby/jruby/rack/session_store.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def get_servlet_session(env, create = false)
7171

7272
private # Rack::Session::Abstract::ID overrides :
7373

74-
def session_class; ::JRuby::Rack::Session::SessionHash; end # Rack 1.5
74+
def session_class
75+
::JRuby::Rack::Session::SessionHash
76+
end
7577

7678
def initialize_sid
7779
nil # dummy method - not usable with servlet API

src/spec/ruby/jruby/rack/integration_spec.rb

+2-13
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,7 @@ def expect_to_have_monkey_patched_chunked
407407
script = %{
408408
headers = { 'Transfer-Encoding' => 'chunked' }
409409
410-
body = [ \"1\".freeze, \"\", \"\nsecond\" ]
411-
412-
if defined? Rack::Chunked::Body # Rails 3.x
413-
body = Rack::Chunked::Body.new body
414-
else # Rack 1.1 / 1.2
415-
chunked = Rack::Chunked.new(nil)
416-
chunked.chunk(200, headers, body)
417-
body = chunked
418-
end
410+
body = Rack::Chunked::Body.new [ \"1\".freeze, \"\", \"\nsecond\" ]
419411
420412
parts = []; body.each { |part| parts << part }
421413
parts.join
@@ -431,10 +423,7 @@ def initialize_rails(env = nil, servlet_context = @servlet_context)
431423
servlet_context = new_servlet_context(base)
432424
end
433425
listener = org.jruby.rack.rails.RailsServletContextListener.new
434-
# Travis-CI might have RAILS_ENV=test set, which is not desired for us :
435-
#if ENV['RAILS_ENV'] || ENV['RACK_ENV']
436-
#ENV['RAILS_ENV'] = env; ENV.delete('RACK_ENV')
437-
#end
426+
438427
the_env = "GEM_HOME=#{ENV['GEM_HOME']},GEM_PATH=#{ENV['GEM_PATH']}"
439428
the_env << "\nRAILS_ENV=#{env}" if env
440429
servlet_context.addInitParameter("jruby.runtime.env", the_env)

src/spec/ruby/jruby/rack/response_spec.rb

+2-8
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,8 @@ class << value; undef_method :each; end if value.respond_to?(:each)
170170
]
171171

172172
with_dechunk do
173-
if defined? Rack::Chunked::Body # Rails 3.x
174-
body = Rack::Chunked::Body.new body
175-
response = JRuby::Rack::Response.new([ 200, headers, body ])
176-
else # Rails 2.3 -> Rack 1.1
177-
chunked = Rack::Chunked.new nil # nil application
178-
response = JRuby::Rack::Response.new chunked.chunk(200, headers, body)
179-
end
180-
173+
body = Rack::Chunked::Body.new body
174+
response = JRuby::Rack::Response.new([ 200, headers, body ])
181175
response.write_headers(response_environment)
182176

183177
times = 0

src/spec/ruby/rack/handler/servlet_spec.rb

+3-15
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,7 @@ def getAttributeNames
642642
request.logger.should be nil # we do not setup rack.logger
643643

644644
lambda { request.scheme }.should_not raise_error
645-
if Rack.release >= '1.3' # rack 1.3.x 1.4.x
646-
request.scheme.should == 'https' # X-Forwarded-Proto
647-
else
648-
request.scheme.should == 'http' # Rails 3.0 / 2.3
649-
end
645+
request.scheme.should == 'https' # X-Forwarded-Proto
650646

651647
lambda { request.port }.should_not raise_error
652648
request.port.should == 80
@@ -662,19 +658,11 @@ def getAttributeNames
662658

663659
if defined?(request.base_url)
664660
lambda { request.base_url }.should_not raise_error
665-
if Rack.release >= '1.3' # Rails >= 3.1.x
666-
request.base_url.should == 'https://serverhost:80'
667-
else
668-
request.base_url.should == 'http://serverhost'
669-
end
661+
request.base_url.should == 'https://serverhost:80'
670662
end
671663

672664
lambda { request.url }.should_not raise_error
673-
if Rack.release >= '1.3' # Rails >= 3.1.x
674-
request.url.should == 'https://serverhost:80/main/app1/path/info?hello=there'
675-
else
676-
request.url.should == 'http://serverhost/main/app1/path/info?hello=there'
677-
end
665+
request.url.should == 'https://serverhost:80/main/app1/path/info?hello=there'
678666
end
679667

680668
describe 'dumped-and-loaded' do

0 commit comments

Comments
 (0)