Custom response for weird http verbs like PROPFIND / PURGE / OPTIONS etc

Getting lots of strange errors about weird http verbs being used, this rack middleware will help 🙂

Setup

config.middleware.use 'HttpVerbResponder',
  'PROPFIND' => [404, {}, 'Not supported'],
  'PURGE' => [404, {}, 'Not supported'], # e.g. varnish
  'OPTIONS' => [200, {"Access-Control-Allow-Origin" => "*", "Access-Control-Max-Age" => '1000'},'OK"] # CORS

Code

class HttpVerbResponder
  def initialize(app, options={})
    @app = app
    @options = options
  end

  def call(env, options={})
    if response = @options[env['REQUEST_METHOD']]
      response
    else
      @app.call(env)
    end
  end
end

Test

curl -X PURGE your-url.com

2 thoughts on “Custom response for weird http verbs like PROPFIND / PURGE / OPTIONS etc

  1. What do you think about filtering weird http requests in nginx ?

    if ($request_method = PROPFIND) { return 404; }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s