20300: Fix crash on empty Content-Type header.
[arvados.git] / services / api / config / initializers / clear_empty_content_type.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 # Rails handler stack crashes if the request Content-Type header value
6 # is "", which is sometimes the case in GET requests from
7 # ruby-google-api-client (which have no body content anyway).
8 #
9 # This middleware deletes such headers, so a request with an empty
10 # Content-Type value is equivalent to a missing Content-Type header.
11 class ClearEmptyContentType
12   def initialize(app=nil, options=nil)
13     @app = app
14   end
15
16   def call(env)
17     if env["CONTENT_TYPE"] == ""
18       env.delete("CONTENT_TYPE")
19     end
20     @app.call(env) if @app.respond_to?(:call)
21   end
22 end
23
24 Server::Application.configure do
25   config.middleware.use ClearEmptyContentType
26 end