Skip to content

Commit 91d7d30

Browse files
retookares
authored andcommitted
When handling OPTION calls ignore both 'Date' and 'Allow' headers
to decide if call has been handeled If not, no OPTION calls will be passed down to the rack app due to the fact that some implementations of DefaultServlet (i.e. Jetty) also sets 'Date' Fixes #205
1 parent 91efe06 commit 91d7d30

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
import java.io.PrintWriter;
1313
import java.lang.reflect.InvocationTargetException;
1414
import java.lang.reflect.Method;
15+
import java.util.Arrays;
1516
import java.util.Collection;
1617
import java.util.Collections;
18+
import java.util.HashSet;
19+
import java.util.Set;
1720

1821
import javax.servlet.ServletOutputStream;
1922
import javax.servlet.http.HttpServletRequest;
@@ -230,12 +233,14 @@ public boolean isHandled(final HttpServletRequest request) {
230233
// not to happen but there's all kind of beasts out there
231234
return false;
232235
}
236+
// Tomcat's DefaultServlet sets 'Allow' header but Jetty also sets the 'Date' header with its servlet
237+
// ... if any other headers occur beside 'Allow' and 'Date' we consider this request handled
233238
for ( final String headerName : headerNames ) {
234-
if ( ! "Allow".equals( headerName ) ) {
235-
return handled = true; // not just Allow header - consider handled
239+
if ( ! "Allow".equals( headerName ) || ! "Date".equals( headerName ) ) {
240+
return handled = true;
236241
}
237242
}
238-
return false; // OPTIONS with only Allow header set - unhandled
243+
return false; // OPTIONS with only 'Allow' (and/or 'Date') header set - unhandled
239244
}
240245
return handled = true;
241246
}

src/spec/ruby/rack/servlet/response_capture_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@
6565
expect( response_capture.isHandled(servlet_request) ).to be false
6666
end
6767

68+
it "is not considered handled when only Allow or Date header is added with OPTIONS" do
69+
servlet_request.method = 'OPTIONS'
70+
71+
# NOTE: Jetty sets both Date and Allow in DefaultServlet#doOptions
72+
response_capture.addHeader "Allow", "GET, POST, OPTIONS"
73+
response_capture.addHeader "Date", Time.now.httpdate
74+
75+
expect( response_capture.isHandled(servlet_request) ).to be false
76+
end
77+
6878
it "is considered handled when more than Allow header is added with OPTIONS" do
6979
pending "need Servlet API 3.0" unless servlet_30?
7080

@@ -100,4 +110,4 @@ def servlet_30?
100110
Java::JavaClass.for_name('javax.servlet.AsyncContext') rescue nil
101111
end
102112

103-
end
113+
end

0 commit comments

Comments
 (0)