Class: RackEmptyBodyFix

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_empty_body_fix.rb

Overview

Rack Empty Post Body Fix

This class is a Rack Middleware that checks for an empty POST body (an MSIE issue, naturally) and errors out if found.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackEmptyBodyFix

Returns a new instance of RackEmptyBodyFix.



7
8
9
# File 'lib/rack_empty_body_fix.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack_empty_body_fix.rb', line 11

def call(env)
  if env['POST_BODY']
    body = env['POST_BODY'].read

    if body && body.empty?
      return [408, { 'Content-Type' => 'text/plain' }, ['empty body']]
    end

    env['POST_BODY'].rewind
  end

  @app.call env
end