Reproduction:
class API < Grape::API
before do
header "X-Test-A", "Success"
end
class HeaderTest < Grape::Middleware::Base
def before
endpoint = env['api.endpoint']
endpoint.header "X-Test-B", "Success"
end
end
use HeaderTest
get '/' do
present ""
end
end
Expected result:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0
Cache-Control: max-age=0, private, must-revalidate
Connection: keep-alive
X-Test-A: Success
X-Test-B: Success
Server: thin
Actual result:
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain
Content-Length: 39
Cache-Control: max-age=0, private, must-revalidate
Connection: keep-alive
Server: thin
undefined method `[]=' for nil:NilClass
Cause: Headers are sent before any before calls in middleware Before is called before any response is created.
Workaround: Set headers in after (@app_response[1])
Reproduction:
Expected result:
Actual result:
Cause:
Headers are sent before anyBefore is called before any response is created.beforecalls in middlewareWorkaround: Set headers in
after(@app_response[1])