class HTTPX::Transcoder::Multipart::Decoder

  1. lib/httpx/transcoder/multipart/decoder.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. call

Included modules

  1. HTTPX::Utils

Constants

BOUNDARY_RE = /;\s*boundary=([^;]+)/i.freeze  
CRLF = "\r\n"  
MULTIPART_CONTENT_DISPOSITION = /Content-Disposition:.*;\s*name=(#{VALUE})/ni.freeze  
MULTIPART_CONTENT_ID = /Content-ID:\s*([^#{CRLF}]*)/ni.freeze  
MULTIPART_CONTENT_TYPE = /Content-Type: (.*)#{CRLF}/ni.freeze  
WINDOW_SIZE = 2 << 14  

Public Class methods

new(response)
[show source]
   # File lib/httpx/transcoder/multipart/decoder.rb
30 def initialize(response)
31   @boundary = begin
32     m = response.headers["content-type"].to_s[BOUNDARY_RE, 1]
33     raise Error, "no boundary declared in content-type header" unless m
34 
35     m.strip
36   end
37   @buffer = "".b
38   @parts = {}
39   @intermediate_boundary = "--#{@boundary}"
40   @state = :idle
41 end

Public Instance methods

call(response, *)
[show source]
   # File lib/httpx/transcoder/multipart/decoder.rb
43 def call(response, *)
44   response.body.each do |chunk|
45     @buffer << chunk
46 
47     parse
48   end
49 
50   raise Error, "invalid or unsupported multipart format" unless @buffer.empty?
51 
52   @parts
53 end