File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44Bundler . require ( *Rails . groups )
55
6- # Catch unknown HTTP methods, routing errors, and mark /upload as binary
7- class MethodGuard
8- VALID_METHODS = %w[ GET HEAD POST PUT DELETE PATCH OPTIONS TRACE ] . to_set . freeze
9-
6+ # Mark /upload as binary so Rack skips form parameter parsing
7+ class MarkUploadAsBinary
108 def initialize ( app )
119 @app = app
1210 end
1311
1412 def call ( env )
15- unless VALID_METHODS . include? ( env [ 'REQUEST_METHOD' ] )
16- return [ 405 , { 'content-type' => 'text/plain' } , [ 'Method Not Allowed' ] ]
17- end
18- # Mark /upload as binary so Rack skips form parameter parsing
1913 if env [ 'PATH_INFO' ] == '/upload'
2014 env [ 'CONTENT_TYPE' ] = 'application/octet-stream'
2115 end
2216 @app . call ( env )
23- rescue => e
24- if e . class . name . include? ( 'UnknownHttpMethod' ) || e . class . name . include? ( 'RoutingError' )
25- [ 400 , { 'content-type' => 'text/plain' } , [ 'Bad Request' ] ]
26- else
27- raise
28- end
2917 end
3018end
3119
@@ -65,7 +53,7 @@ class BenchmarkApp < Rails::Application
6553
6654 # Add gzip support
6755 config . middleware . insert 0 , Rack ::Deflater
68- config . middleware . insert 0 , MethodGuard
56+ config . middleware . insert 0 , MarkUploadAsBinary
6957 config . middleware . insert 0 , MarkAsIOBoundThreads
7058
7159 # Silence logging
You can’t perform that action at this time.
0 commit comments