Skip to content

Commit

Permalink
Remove old Rack 1.x / Rails < 3 compatibility code
Browse files Browse the repository at this point in the history
We are only supporting Rack 2.x onwards now anyway.
  • Loading branch information
chadlwilson committed Jan 23, 2025
1 parent 94c5383 commit 197853f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 63 deletions.
15 changes: 1 addition & 14 deletions src/main/java/org/jruby/rack/servlet/ResponseCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public boolean isHandled(final HttpServletRequest request) {

// consider HTTP OPTIONS with "Allow" header unhandled :
if ( request != null && "OPTIONS".equals( request.getMethod() ) ) {
final Collection<String> headerNames = getHeaderNamesOrNull();
final Collection<String> headerNames = getHeaderNames();
if ( headerNames == null || headerNames.isEmpty() ) {
// not to happen but there's all kind of beasts out there
return false;
Expand Down Expand Up @@ -277,17 +277,4 @@ public void setHandledByDefault(boolean handledByDefault) {
public boolean isOutputAccessed() {
return output != null;
}

@SuppressWarnings("unchecked")
private Collection<String> getHeaderNamesOrNull() {
// NOTE: getHeaderNames since Servlet API 3.0 JRuby-Rack 1.1 still supports 2.5
try {
final Method getHeaderNames = getResponse().getClass().getMethod("getHeaderNames");
return (Collection<String>) getHeaderNames.invoke( getResponse() );
}
catch (NoSuchMethodException e) { return null; }
catch (IllegalAccessException e) { return null; }
catch (InvocationTargetException e) { return null; }
}

}
12 changes: 0 additions & 12 deletions src/main/ruby/jruby/rack/chunked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,4 @@ def each(&block)
@body.each(&block) # no-chunking on servlets
end

end if defined? Rack::Chunked::Body

unless defined? Rack::Chunked::Body # Rack 1.1

Rack::Chunked.class_eval do

def each(&block)
@body.each(&block) # no-chunking on servlets
end

end

end
4 changes: 3 additions & 1 deletion src/main/ruby/jruby/rack/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def get_servlet_session(env, create = false)

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

def session_class; ::JRuby::Rack::Session::SessionHash; end # Rack 1.5
def session_class
::JRuby::Rack::Session::SessionHash
end

def initialize_sid
nil # dummy method - not usable with servlet API
Expand Down
15 changes: 2 additions & 13 deletions src/spec/ruby/jruby/rack/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,7 @@ def expect_to_have_monkey_patched_chunked
script = %{
headers = { 'Transfer-Encoding' => 'chunked' }
body = [ \"1\".freeze, \"\", \"\nsecond\" ]
if defined? Rack::Chunked::Body # Rails 3.x
body = Rack::Chunked::Body.new body
else # Rack 1.1 / 1.2
chunked = Rack::Chunked.new(nil)
chunked.chunk(200, headers, body)
body = chunked
end
body = Rack::Chunked::Body.new [ \"1\".freeze, \"\", \"\nsecond\" ]
parts = []; body.each { |part| parts << part }
parts.join
Expand All @@ -431,10 +423,7 @@ def initialize_rails(env = nil, servlet_context = @servlet_context)
servlet_context = new_servlet_context(base)
end
listener = org.jruby.rack.rails.RailsServletContextListener.new
# Travis-CI might have RAILS_ENV=test set, which is not desired for us :
#if ENV['RAILS_ENV'] || ENV['RACK_ENV']
#ENV['RAILS_ENV'] = env; ENV.delete('RACK_ENV')
#end

the_env = "GEM_HOME=#{ENV['GEM_HOME']},GEM_PATH=#{ENV['GEM_PATH']}"
the_env << "\nRAILS_ENV=#{env}" if env
servlet_context.addInitParameter("jruby.runtime.env", the_env)
Expand Down
10 changes: 2 additions & 8 deletions src/spec/ruby/jruby/rack/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,8 @@ class << value; undef_method :each; end if value.respond_to?(:each)
]

with_dechunk do
if defined? Rack::Chunked::Body # Rails 3.x
body = Rack::Chunked::Body.new body
response = JRuby::Rack::Response.new([ 200, headers, body ])
else # Rails 2.3 -> Rack 1.1
chunked = Rack::Chunked.new nil # nil application
response = JRuby::Rack::Response.new chunked.chunk(200, headers, body)
end

body = Rack::Chunked::Body.new body
response = JRuby::Rack::Response.new([ 200, headers, body ])
response.write_headers(response_environment)

times = 0
Expand Down
18 changes: 3 additions & 15 deletions src/spec/ruby/rack/handler/servlet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,7 @@ def getAttributeNames
request.logger.should be nil # we do not setup rack.logger

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

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

if defined?(request.base_url)
lambda { request.base_url }.should_not raise_error
if Rack.release >= '1.3' # Rails >= 3.1.x
request.base_url.should == 'https://serverhost:80'
else
request.base_url.should == 'http://serverhost'
end
request.base_url.should == 'https://serverhost:80'
end

lambda { request.url }.should_not raise_error
if Rack.release >= '1.3' # Rails >= 3.1.x
request.url.should == 'https://serverhost:80/main/app1/path/info?hello=there'
else
request.url.should == 'http://serverhost/main/app1/path/info?hello=there'
end
request.url.should == 'https://serverhost:80/main/app1/path/info?hello=there'
end

describe 'dumped-and-loaded' do
Expand Down

0 comments on commit 197853f

Please sign in to comment.