class RackEmptyBodyFix

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.

Public Class Methods

new(app) click to toggle source
# File lib/rack_empty_body_fix.rb, line 7
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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