Class: Coolio::Http::Payload::UrlEncoded

Inherits:
Base
  • Object
show all
Defined in:
lib/cool.io/http/payload.rb

Instance Method Summary collapse

Methods inherited from Base

#close, #flatten_params, #flatten_params_array, #initialize, #inspect, #read, #short_inspect, #size

Constructor Details

This class inherits a constructor from Coolio::Http::Payload::Base

Instance Method Details

#build_stream(params = nil) ⇒ Object



144
145
146
147
148
149
# File 'lib/cool.io/http/payload.rb', line 144

def build_stream(params = nil)
  @stream = StringIO.new(flatten_params(params).collect do |entry|
    "#{entry[0]}=#{handle_key(entry[1])}"
  end.join("&"))
  @stream.seek(0)
end

#handle_key(key) ⇒ Object

for UrlEncoded escape the keys



152
153
154
# File 'lib/cool.io/http/payload.rb', line 152

def handle_key key
  URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

#headersObject



156
157
158
# File 'lib/cool.io/http/payload.rb', line 156

def headers
  super.merge({'Content-Type' => 'application/x-www-form-urlencoded'})
end