Skip to content

Commit 5b5b504

Browse files
committed
[rails] Remove Methodguard middleware
1 parent 03b0225 commit 5b5b504

2 files changed

Lines changed: 0 additions & 30 deletions

File tree

frameworks/rails/config/application.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,6 @@
33

44
Bundler.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.
337
class 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

frameworks/sinatra/puma.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
bind "tcp://0.0.0.0:8080"
77
bind "ssl://0.0.0.0:8081?cert=#{tls_cert_path}&key=#{tls_key_path}"
88

9-
# Allow all HTTP methods so unknown ones reach Rack middleware (returned as 405)
10-
supported_http_methods :any
11-
129
preload_app!
1310

1411
before_fork do

0 commit comments

Comments
 (0)