Class: Riddl::Protocols::HTTP::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/http/parser.rb

Constant Summary collapse

MULTIPART_CONTENT_TYPES =
[
  #{{{
  'multipart/form-data',
  'multipart/related',
  'multipart/mixed'
  #}}}
].freeze
FORM_CONTENT_TYPES =

}}}

[
  #{{{
  'application/x-www-form-urlencoded'
  #}}}
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_string, input, content_type, content_length, content_disposition, content_id, riddl_type) ⇒ Parser

Returns a new instance of Parser.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/ruby/riddl/protocols/http/parser.rb', line 161

def initialize(query_string,input,content_type,content_length,content_disposition,content_id,riddl_type)
  #{{{
  # rewind because in some cases it is not at start (when multipart without length)

  begin
    input.rewind if input.respond_to?(:rewind)
  rescue Errno::ESPIPE
    # Handles exceptions raised by input streams that cannot be rewound
    # such as when using plain CGI under Apache
  end

  media_type = content_type && content_type.split(/\s*[;,]\s*/, 2).first.downcase
  @params = Riddl::Parameter::Array.new
  parse_nested_query(query_string,:query)
  if MULTIPART_CONTENT_TYPES.include?(media_type)
    parse_multipart(input,content_type,content_length.to_i)
  elsif FORM_CONTENT_TYPES.include?(media_type)
    # sub is a fix for Safari Ajax postings that always append \0
    parse_nested_query(input.read.sub(/\0\z/, ''),:body)
  else
    parse_content(input,content_type,content_length.to_i,content_disposition||'',content_id||'',riddl_type||'')
  end

  begin
    input.rewind if input.respond_to?(:rewind)
  rescue Errno::ESPIPE
    # Handles exceptions raised by input streams that cannot be rewound
    # such as when using plain CGI under Apache
  end
  #}}}
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



193
194
195
# File 'lib/ruby/riddl/protocols/http/parser.rb', line 193

def params
  @params
end