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-
10- def initialize ( app )
11- @app = app
12- end
13-
14- 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
19- if env [ 'PATH_INFO' ] == '/upload'
20- env [ 'CONTENT_TYPE' ] = 'application/octet-stream'
21- end
22- @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
29- end
30- end
31-
326# Threads marked as IO bound are allowed to go over Puma's max thread limit.
337class MarkAsIOBoundThreads
348 def initialize ( app )
@@ -65,7 +39,6 @@ class BenchmarkApp < Rails::Application
6539
6640 # Add gzip support
6741 config . middleware . insert 0 , Rack ::Deflater
68- config . middleware . insert 0 , MethodGuard
6942 config . middleware . insert 0 , MarkAsIOBoundThreads
7043
7144 # Silence logging
You can’t perform that action at this time.
0 commit comments