Methods
- body
- body=
- content
- contenttype
- contenttype=
- create_query_multipart_str
- create_query_part_str
- dump
- escape
- escape_query
- header
- header=
- load
- mime_type
- multiparam_query?
- new
- new_request
- new_response
- reason
- reason=
- status
- status=
- sync_body
- sync_header
- version
- version=
Classes and Modules
Class HTTP::Message::BodyClass HTTP::Message::Headers
Constants
CRLF | = | "\r\n" |
Public Class methods
[ show source ]
# File lib/facets/more/http.rb, line 489 def create_query_multipart_str(query, boundary) if multiparam_query?(query) query.collect { |attr, value| value ||= '' if value.is_a? File params = { 'filename' => value.path, # Creation time is not available from File::Stat # 'creation-date' => value.ctime.rfc822, 'modification-date' => value.mtime.rfc822, 'read-date' => value.atime.rfc822, } param_str = params.to_a.collect { |k, v| "#{k}=\"#{v}\"" }.join("; ") "--#{boundary}\n" + %{Content-Disposition: form-data; name="#{attr.to_s}"; #{param_str}\n} + "Content-Type: #{mime_type(value.path)}\n\n#{value.read}\n" else "--#{boundary}\n" + %{Content-Disposition: form-data; name="#{attr.to_s}"\n} + "\n#{value.to_s}\n" end }.join('') + "--#{boundary}--\n" else query.to_s end end
[ show source ]
# File lib/facets/more/http.rb, line 481 def create_query_part_str(query) if multiparam_query?(query) escape_query(query) else query.to_s end end
from CGI.escape
[ show source ]
# File lib/facets/more/http.rb, line 529 def escape(str) str.gsub(/([^ a-zA-Z0-9_.-]+)/n) { '%' + $1.unpack('H2' * $1.size).join('%').upcase }.tr(' ', '+') end
[ show source ]
# File lib/facets/more/http.rb, line 522 def escape_query(query) query.collect { |attr, value| escape(attr.to_s) << '=' << escape(value.to_s) }.join('&') end
[ show source ]
# File lib/facets/more/http.rb, line 535 def mime_type(path) case path when /.(htm|html)$/ 'text/html' when /.doc$/ 'application/msword' else 'text/plain' end end
[ show source ]
# File lib/facets/more/http.rb, line 518 def multiparam_query?(query) query.is_a?(Array) or query.is_a?(Hash) end
[ show source ]
# File lib/facets/more/http.rb, line 385 def initialize @body = @header = nil end
[ show source ]
# File lib/facets/more/http.rb, line 394 def self.new_request(method, uri, query = nil, body = nil, proxy = nil, boundary = nil) m = self.__new m.header = Headers.new m.header.init_request(method, uri, query, proxy) m.body = Body.new(body, nil, nil, nil, boundary) m end
[ show source ]
# File lib/facets/more/http.rb, line 403 def self.new_response(body = '') m = self.__new m.header = Headers.new m.header.init_response(Status::OK) m.body = Body.new(body) m end
Public Instance methods
[ show source ]
# File lib/facets/more/http.rb, line 439 def body @body end
[ show source ]
# File lib/facets/more/http.rb, line 443 def body=(body) @body = body sync_header end
[ show source ]
# File lib/facets/more/http.rb, line 435 def content @body.content end
[ show source ]
# File lib/facets/more/http.rb, line 472 def contenttype @header.contenttype end
[ show source ]
# File lib/facets/more/http.rb, line 476 def contenttype=(contenttype) @header.contenttype = contenttype end
[ show source ]
# File lib/facets/more/http.rb, line 411 def dump(dev = '') sync_header dev = header.dump(dev) dev << CRLF dev = body.dump(dev) if body dev end
[ show source ]
# File lib/facets/more/http.rb, line 426 def header @header end
[ show source ]
# File lib/facets/more/http.rb, line 430 def header=(header) @header = header sync_body end
[ show source ]
# File lib/facets/more/http.rb, line 419 def load(str) buf = str.dup unless self.header.load(buf) self.body.load(buf) end end
[ show source ]
# File lib/facets/more/http.rb, line 464 def reason @header.reason_phrase end
[ show source ]
# File lib/facets/more/http.rb, line 468 def reason=(reason) @header.reason_phrase = reason end
[ show source ]
# File lib/facets/more/http.rb, line 448 def status @header.response_status_code end
[ show source ]
# File lib/facets/more/http.rb, line 452 def status=(status) @header.response_status_code = status end
[ show source ]
# File lib/facets/more/http.rb, line 456 def version @header.http_version end
[ show source ]
# File lib/facets/more/http.rb, line 460 def version=(version) @header.http_version = version end
Private Instance methods
[ show source ]
# File lib/facets/more/http.rb, line 558 def sync_body if @header and @body @body.type = @header.body_type @body.charset = @header.body_charset @body.size = @header.body_size @body.date = @header.body_date end end
[ show source ]
# File lib/facets/more/http.rb, line 549 def sync_header if @header and @body @header.body_type = @body.type @header.body_charset = @body.charset @header.body_size = @body.size @header.body_date = @body.date end end