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

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/parser.rb,
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.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/ruby/riddl/protocols/parser.rb', line 169

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.



201
202
203
# File 'lib/ruby/riddl/protocols/parser.rb', line 201

def params
  @params
end