Class: Weary::Middleware::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/weary/middleware/content_type.rb

Constant Summary

CONTENT_TYPE =
'CONTENT_TYPE'
CONTENT_LENGTH =
'CONTENT_LENGTH'
FORM_URL_ENCODED =
'application/x-www-form-urlencoded'
MULTIPART_FORM =
'multipart/form-data'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, type = FORM_URL_ENCODED) ⇒ ContentType



12
13
14
15
# File 'lib/weary/middleware/content_type.rb', line 12

def initialize(app, type = FORM_URL_ENCODED)
  @app = app
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type



10
11
12
# File 'lib/weary/middleware/content_type.rb', line 10

def type
  @type
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
# File 'lib/weary/middleware/content_type.rb', line 17

def call(env)
  size = length(env['rack.input'])
  env.update CONTENT_TYPE => @type
  env.update CONTENT_LENGTH => size.to_s unless size.nil? or size.zero?
  @app.call(env)
end

#length(input) ⇒ Object



24
25
26
# File 'lib/weary/middleware/content_type.rb', line 24

def length(input)
  input.respond_to?(:size) ? input.size : 0
end