D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
cpanel
/
ea-ruby27
/
root
/
usr
/
share
/
gems
/
doc
/
rack-2.2.10
/
rdoc
/
Rack
/
Multipart
/
Filename :
Parser.html
back
Copy
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>class Rack::Multipart::Parser - rack-2.2.10 Documentation</title> <script type="text/javascript"> var rdoc_rel_prefix = "../../"; var index_rel_prefix = "../../"; </script> <script src="../../js/navigation.js" defer></script> <script src="../../js/search.js" defer></script> <script src="../../js/search_index.js" defer></script> <script src="../../js/searcher.js" defer></script> <script src="../../js/darkfish.js" defer></script> <link href="../../css/fonts.css" rel="stylesheet"> <link href="../../css/rdoc.css" rel="stylesheet"> <body id="top" role="document" class="class"> <nav role="navigation"> <div id="project-navigation"> <div id="home-section" role="region" title="Quick navigation" class="nav-section"> <h2> <a href="../../index.html" rel="home">Home</a> </h2> <div id="table-of-contents-navigation"> <a href="../../table_of_contents.html#pages">Pages</a> <a href="../../table_of_contents.html#classes">Classes</a> <a href="../../table_of_contents.html#methods">Methods</a> </div> </div> <div id="search-section" role="search" class="project-section initially-hidden"> <form action="#" method="get" accept-charset="utf-8"> <div id="search-field-wrapper"> <input id="search-field" role="combobox" aria-label="Search" aria-autocomplete="list" aria-controls="search-results" type="text" name="search" placeholder="Search" spellcheck="false" title="Type to search, Up and Down to navigate, Enter to load"> </div> <ul id="search-results" aria-label="Search Results" aria-busy="false" aria-expanded="false" aria-atomic="false" class="initially-hidden"></ul> </form> </div> </div> <div id="class-metadata"> <div id="parent-class-section" class="nav-section"> <h3>Parent</h3> <p class="link">Object </div> <!-- Method Quickref --> <div id="method-list-section" class="nav-section"> <h3>Methods</h3> <ul class="link-list" role="directory"> <li ><a href="#method-c-new">::new</a> <li ><a href="#method-c-parse">::parse</a> <li ><a href="#method-c-parse_boundary">::parse_boundary</a> <li ><a href="#method-i-consume_boundary">#consume_boundary</a> <li ><a href="#method-i-full_boundary">#full_boundary</a> <li ><a href="#method-i-get_filename">#get_filename</a> <li ><a href="#method-i-handle_consume_token">#handle_consume_token</a> <li ><a href="#method-i-handle_empty_content-21">#handle_empty_content!</a> <li ><a href="#method-i-handle_fast_forward">#handle_fast_forward</a> <li ><a href="#method-i-handle_mime_body">#handle_mime_body</a> <li ><a href="#method-i-handle_mime_head">#handle_mime_head</a> <li ><a href="#method-i-on_read">#on_read</a> <li ><a href="#method-i-result">#result</a> <li ><a href="#method-i-run_parser">#run_parser</a> <li ><a href="#method-i-tag_multipart_encoding">#tag_multipart_encoding</a> </ul> </div> </div> </nav> <main role="main" aria-labelledby="class-Rack::Multipart::Parser"> <h1 id="class-Rack::Multipart::Parser" class="class"> class Rack::Multipart::Parser </h1> <section class="description"> </section> <section id="5Buntitled-5D" class="documentation-section"> <section class="constants-list"> <header> <h3>Constants</h3> </header> <dl> <dt id="BOUNDARY_REGEX">BOUNDARY_REGEX <dd> <dt id="BUFSIZE">BUFSIZE <dd> <dt id="CHARSET">CHARSET <dd> <dt id="EMPTY">EMPTY <dd> <dt id="MultipartInfo">MultipartInfo <dd> <dt id="TEMPFILE_FACTORY">TEMPFILE_FACTORY <dd> <dt id="TEXT_PLAIN">TEXT_PLAIN <dd> </dl> </section> <section class="attribute-method-details" class="method-section"> <header> <h3>Attributes</h3> </header> <div id="attribute-i-state" class="method-detail"> <div class="method-heading attribute-method-heading"> <span class="method-name">state</span><span class="attribute-access-type">[R]</span> </div> <div class="method-description"> </div> </div> </section> <section id="public-class-5Buntitled-5D-method-details" class="method-section"> <header> <h3>Public Class Methods</h3> </header> <div id="method-c-new" class="method-detail "> <div class="method-heading"> <span class="method-name">new</span><span class="method-args">(boundary, tempfile, bufsize, query_parser)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="new-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 180</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">boundary</span>, <span class="ruby-identifier">tempfile</span>, <span class="ruby-identifier">bufsize</span>, <span class="ruby-identifier">query_parser</span>) <span class="ruby-ivar">@query_parser</span> = <span class="ruby-identifier">query_parser</span> <span class="ruby-ivar">@params</span> = <span class="ruby-identifier">query_parser</span>.<span class="ruby-identifier">make_params</span> <span class="ruby-ivar">@boundary</span> = <span class="ruby-node">"--#{boundary}"</span> <span class="ruby-ivar">@bufsize</span> = <span class="ruby-identifier">bufsize</span> <span class="ruby-ivar">@full_boundary</span> = <span class="ruby-ivar">@boundary</span> <span class="ruby-ivar">@end_boundary</span> = <span class="ruby-ivar">@boundary</span> <span class="ruby-operator">+</span> <span class="ruby-string">'--'</span> <span class="ruby-ivar">@state</span> = <span class="ruby-value">:FAST_FORWARD</span> <span class="ruby-ivar">@mime_index</span> = <span class="ruby-value">0</span> <span class="ruby-ivar">@collector</span> = <span class="ruby-constant">Collector</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">tempfile</span> <span class="ruby-ivar">@sbuf</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">""</span>.<span class="ruby-identifier">dup</span>) <span class="ruby-ivar">@body_regex</span> = <span class="ruby-regexp">/(?:#{EOL})?#{Regexp.quote(@boundary)}(?:#{EOL}|--)/m</span> <span class="ruby-ivar">@end_boundary_size</span> = <span class="ruby-identifier">boundary</span>.<span class="ruby-identifier">bytesize</span> <span class="ruby-operator">+</span> <span class="ruby-value">6</span> <span class="ruby-comment"># (-- at start, -- at finish, EOL at end)</span> <span class="ruby-ivar">@rx_max_size</span> = <span class="ruby-constant">EOL</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@boundary</span>.<span class="ruby-identifier">bytesize</span> <span class="ruby-operator">+</span> [<span class="ruby-constant">EOL</span>.<span class="ruby-identifier">size</span>, <span class="ruby-string">'--'</span>.<span class="ruby-identifier">size</span>].<span class="ruby-identifier">max</span> <span class="ruby-ivar">@head_regex</span> = <span class="ruby-regexp">/(.*?#{EOL})#{EOL}/m</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-c-parse" class="method-detail "> <div class="method-heading"> <span class="method-name">parse</span><span class="method-args">(io, content_length, content_type, tmpfile, bufsize, qp)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="parse-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 66</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parse</span>(<span class="ruby-identifier">io</span>, <span class="ruby-identifier">content_length</span>, <span class="ruby-identifier">content_type</span>, <span class="ruby-identifier">tmpfile</span>, <span class="ruby-identifier">bufsize</span>, <span class="ruby-identifier">qp</span>) <span class="ruby-keyword">return</span> <span class="ruby-constant">EMPTY</span> <span class="ruby-keyword">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">content_length</span> <span class="ruby-identifier">boundary</span> = <span class="ruby-identifier">parse_boundary</span> <span class="ruby-identifier">content_type</span> <span class="ruby-keyword">return</span> <span class="ruby-constant">EMPTY</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">boundary</span> <span class="ruby-identifier">io</span> = <span class="ruby-constant">BoundedIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">io</span>, <span class="ruby-identifier">content_length</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">content_length</span> <span class="ruby-identifier">outbuf</span> = <span class="ruby-constant">String</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">parser</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">boundary</span>, <span class="ruby-identifier">tmpfile</span>, <span class="ruby-identifier">bufsize</span>, <span class="ruby-identifier">qp</span>) <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">on_read</span> <span class="ruby-identifier">io</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">bufsize</span>, <span class="ruby-identifier">outbuf</span>) <span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span> <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">state</span> <span class="ruby-operator">==</span> <span class="ruby-value">:DONE</span> <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">on_read</span> <span class="ruby-identifier">io</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">bufsize</span>, <span class="ruby-identifier">outbuf</span>) <span class="ruby-keyword">end</span> <span class="ruby-identifier">io</span>.<span class="ruby-identifier">rewind</span> <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">result</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-c-parse_boundary" class="method-detail "> <div class="method-heading"> <span class="method-name">parse_boundary</span><span class="method-args">(content_type)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="parse_boundary-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 59</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parse_boundary</span>(<span class="ruby-identifier">content_type</span>) <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">content_type</span> <span class="ruby-identifier">data</span> = <span class="ruby-identifier">content_type</span>.<span class="ruby-identifier">match</span>(<span class="ruby-constant">MULTIPART</span>) <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">data</span> <span class="ruby-identifier">data</span>[<span class="ruby-value">1</span>] <span class="ruby-keyword">end</span></pre> </div> </div> </div> </section> <section id="public-instance-5Buntitled-5D-method-details" class="method-section"> <header> <h3>Public Instance Methods</h3> </header> <div id="method-i-on_read" class="method-detail "> <div class="method-heading"> <span class="method-name">on_read</span><span class="method-args">(content)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="on_read-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 199</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">on_read</span>(<span class="ruby-identifier">content</span>) <span class="ruby-identifier">handle_empty_content!</span>(<span class="ruby-identifier">content</span>) <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">content</span> <span class="ruby-identifier">run_parser</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-result" class="method-detail "> <div class="method-heading"> <span class="method-name">result</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="result-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 205</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">result</span> <span class="ruby-ivar">@collector</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">part</span><span class="ruby-operator">|</span> <span class="ruby-identifier">part</span>.<span class="ruby-identifier">get_data</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">data</span><span class="ruby-operator">|</span> <span class="ruby-identifier">tag_multipart_encoding</span>(<span class="ruby-identifier">part</span>.<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">part</span>.<span class="ruby-identifier">content_type</span>, <span class="ruby-identifier">part</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">data</span>) <span class="ruby-ivar">@query_parser</span>.<span class="ruby-identifier">normalize_params</span>(<span class="ruby-ivar">@params</span>, <span class="ruby-identifier">part</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">data</span>, <span class="ruby-ivar">@query_parser</span>.<span class="ruby-identifier">param_depth_limit</span>) <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span> <span class="ruby-constant">MultipartInfo</span>.<span class="ruby-identifier">new</span> <span class="ruby-ivar">@params</span>.<span class="ruby-identifier">to_params_hash</span>, <span class="ruby-ivar">@collector</span>.<span class="ruby-identifier">find_all</span>(<span class="ruby-operator">&</span><span class="ruby-value">:file?</span>).<span class="ruby-identifier">map</span>(<span class="ruby-operator">&</span><span class="ruby-value">:body</span>) <span class="ruby-keyword">end</span></pre> </div> </div> </div> </section> <section id="private-instance-5Buntitled-5D-method-details" class="method-section"> <header> <h3>Private Instance Methods</h3> </header> <div id="method-i-consume_boundary" class="method-detail "> <div class="method-heading"> <span class="method-name">consume_boundary</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="consume_boundary-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 302</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">consume_boundary</span> <span class="ruby-keyword">while</span> <span class="ruby-identifier">read_buffer</span> = <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">scan_until</span>(<span class="ruby-constant">BOUNDARY_REGEX</span>) <span class="ruby-keyword">case</span> <span class="ruby-identifier">read_buffer</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword">when</span> <span class="ruby-identifier">full_boundary</span> <span class="ruby-keyword">then</span> <span class="ruby-keyword">return</span> <span class="ruby-value">:BOUNDARY</span> <span class="ruby-keyword">when</span> <span class="ruby-ivar">@end_boundary</span> <span class="ruby-keyword">then</span> <span class="ruby-keyword">return</span> <span class="ruby-value">:END_BOUNDARY</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">eos?</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-full_boundary" class="method-detail "> <div class="method-heading"> <span class="method-name">full_boundary</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="full_boundary-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 300</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">full_boundary</span>; <span class="ruby-ivar">@full_boundary</span>; <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-get_filename" class="method-detail "> <div class="method-heading"> <span class="method-name">get_filename</span><span class="method-args">(head)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="get_filename-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 312</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_filename</span>(<span class="ruby-identifier">head</span>) <span class="ruby-identifier">filename</span> = <span class="ruby-keyword">nil</span> <span class="ruby-keyword">case</span> <span class="ruby-identifier">head</span> <span class="ruby-keyword">when</span> <span class="ruby-constant">RFC2183</span> <span class="ruby-identifier">params</span> = <span class="ruby-constant">Hash</span>[<span class="ruby-operator">*</span><span class="ruby-identifier">head</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-constant">DISPPARM</span>).<span class="ruby-identifier">flat_map</span>(<span class="ruby-operator">&</span><span class="ruby-value">:compact</span>)] <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">params</span>[<span class="ruby-string">'filename'</span>] <span class="ruby-identifier">filename</span> = <span class="ruby-node">$1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/^"(.*)"$/</span> <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">params</span>[<span class="ruby-string">'filename*'</span>] <span class="ruby-identifier">encoding</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">"'"</span>, <span class="ruby-value">3</span>) <span class="ruby-keyword">end</span> <span class="ruby-keyword">when</span> <span class="ruby-constant">BROKEN</span> <span class="ruby-identifier">filename</span> = <span class="ruby-node">$1</span> <span class="ruby-identifier">filename</span> = <span class="ruby-node">$1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/^"(.*)"$/</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">filename</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/%.?.?/</span>).<span class="ruby-identifier">all?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-regexp">/%[0-9a-fA-F]{2}/</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-identifier">s</span>) } <span class="ruby-identifier">filename</span> = <span class="ruby-constant">Utils</span>.<span class="ruby-identifier">unescape_path</span>(<span class="ruby-identifier">filename</span>) <span class="ruby-keyword">end</span> <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">scrub!</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp">/\\[^\\"]/</span> <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/\\(.)/</span>, <span class="ruby-string">'\1'</span>) <span class="ruby-keyword">end</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">encoding</span> <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">force_encoding</span> <span class="ruby-operator">::</span><span class="ruby-constant">Encoding</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">encoding</span>) <span class="ruby-keyword">end</span> <span class="ruby-identifier">filename</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-handle_consume_token" class="method-detail "> <div class="method-heading"> <span class="method-name">handle_consume_token</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="handle_consume_token-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 248</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">handle_consume_token</span> <span class="ruby-identifier">tok</span> = <span class="ruby-identifier">consume_boundary</span> <span class="ruby-comment"># break if we're at the end of a buffer, but not if it is the end of a field</span> <span class="ruby-ivar">@state</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">tok</span> <span class="ruby-operator">==</span> <span class="ruby-value">:END_BOUNDARY</span> <span class="ruby-operator">||</span> (<span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">eos?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">tok</span> <span class="ruby-operator">!=</span> <span class="ruby-value">:BOUNDARY</span>) <span class="ruby-value">:DONE</span> <span class="ruby-keyword">else</span> <span class="ruby-value">:MIME_HEAD</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-handle_empty_content-21" class="method-detail "> <div class="method-heading"> <span class="method-name">handle_empty_content!</span><span class="method-args">(content)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="handle_empty_content-21-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 377</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">handle_empty_content!</span>(<span class="ruby-identifier">content</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">content</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">content</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">EOFError</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-handle_fast_forward" class="method-detail "> <div class="method-heading"> <span class="method-name">handle_fast_forward</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="handle_fast_forward-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 234</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">handle_fast_forward</span> <span class="ruby-identifier">tok</span> = <span class="ruby-identifier">consume_boundary</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">tok</span> <span class="ruby-operator">==</span> <span class="ruby-value">:END_BOUNDARY</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@end_boundary_size</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">eos?</span> <span class="ruby-comment"># stop parsing a buffer if a buffer is only an end boundary.</span> <span class="ruby-ivar">@state</span> = <span class="ruby-value">:DONE</span> <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">tok</span> <span class="ruby-ivar">@state</span> = <span class="ruby-value">:MIME_HEAD</span> <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">EOFError</span>, <span class="ruby-string">"bad content body"</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">rest_size</span> <span class="ruby-operator">>=</span> <span class="ruby-ivar">@bufsize</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-handle_mime_body" class="method-detail "> <div class="method-heading"> <span class="method-name">handle_mime_body</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="handle_mime_body-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 281</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">handle_mime_body</span> <span class="ruby-keyword">if</span> (<span class="ruby-identifier">body_with_boundary</span> = <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">check_until</span>(<span class="ruby-ivar">@body_regex</span>)) <span class="ruby-comment"># check but do not advance the pointer yet</span> <span class="ruby-identifier">body</span> = <span class="ruby-identifier">body_with_boundary</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/#{@body_regex}\z/m</span>, <span class="ruby-string">''</span>) <span class="ruby-comment"># remove the boundary from the string</span> <span class="ruby-ivar">@collector</span>.<span class="ruby-identifier">on_mime_body</span> <span class="ruby-ivar">@mime_index</span>, <span class="ruby-identifier">body</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span> <span class="ruby-comment"># skip \r\n after the content</span> <span class="ruby-ivar">@state</span> = <span class="ruby-value">:CONSUME_TOKEN</span> <span class="ruby-ivar">@mime_index</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">else</span> <span class="ruby-comment"># Save what we have so far</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@rx_max_size</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">rest_size</span> <span class="ruby-identifier">delta</span> = <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">rest_size</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@rx_max_size</span> <span class="ruby-ivar">@collector</span>.<span class="ruby-identifier">on_mime_body</span> <span class="ruby-ivar">@mime_index</span>, <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">peek</span>(<span class="ruby-identifier">delta</span>) <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">delta</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">string</span> = <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">rest</span> <span class="ruby-keyword">end</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-handle_mime_head" class="method-detail "> <div class="method-heading"> <span class="method-name">handle_mime_head</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="handle_mime_head-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 258</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">handle_mime_head</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@sbuf</span>.<span class="ruby-identifier">scan_until</span>(<span class="ruby-ivar">@head_regex</span>) <span class="ruby-identifier">head</span> = <span class="ruby-ivar">@sbuf</span>[<span class="ruby-value">1</span>] <span class="ruby-identifier">content_type</span> = <span class="ruby-identifier">head</span>[<span class="ruby-constant">MULTIPART_CONTENT_TYPE</span>, <span class="ruby-value">1</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span> = <span class="ruby-identifier">head</span>[<span class="ruby-constant">MULTIPART_CONTENT_DISPOSITION</span>, <span class="ruby-value">1</span>] <span class="ruby-identifier">name</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Auth</span><span class="ruby-operator">::</span><span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">Params</span><span class="ruby-operator">::</span><span class="ruby-identifier">dequote</span>(<span class="ruby-identifier">name</span>) <span class="ruby-keyword">else</span> <span class="ruby-identifier">name</span> = <span class="ruby-identifier">head</span>[<span class="ruby-constant">MULTIPART_CONTENT_ID</span>, <span class="ruby-value">1</span>] <span class="ruby-keyword">end</span> <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">get_filename</span>(<span class="ruby-identifier">head</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-identifier">name</span> = <span class="ruby-identifier">filename</span> <span class="ruby-operator">||</span> <span class="ruby-node">"#{content_type || TEXT_PLAIN}[]"</span>.<span class="ruby-identifier">dup</span> <span class="ruby-keyword">end</span> <span class="ruby-ivar">@collector</span>.<span class="ruby-identifier">on_mime_head</span> <span class="ruby-ivar">@mime_index</span>, <span class="ruby-identifier">head</span>, <span class="ruby-identifier">filename</span>, <span class="ruby-identifier">content_type</span>, <span class="ruby-identifier">name</span> <span class="ruby-ivar">@state</span> = <span class="ruby-value">:MIME_BODY</span> <span class="ruby-keyword">else</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-run_parser" class="method-detail "> <div class="method-heading"> <span class="method-name">run_parser</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="run_parser-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 217</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">run_parser</span> <span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span> <span class="ruby-keyword">case</span> <span class="ruby-ivar">@state</span> <span class="ruby-keyword">when</span> <span class="ruby-value">:FAST_FORWARD</span> <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">handle_fast_forward</span> <span class="ruby-operator">==</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">when</span> <span class="ruby-value">:CONSUME_TOKEN</span> <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">handle_consume_token</span> <span class="ruby-operator">==</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">when</span> <span class="ruby-value">:MIME_HEAD</span> <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">handle_mime_head</span> <span class="ruby-operator">==</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">when</span> <span class="ruby-value">:MIME_BODY</span> <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">handle_mime_body</span> <span class="ruby-operator">==</span> <span class="ruby-value">:want_read</span> <span class="ruby-keyword">when</span> <span class="ruby-value">:DONE</span> <span class="ruby-keyword">break</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-tag_multipart_encoding" class="method-detail "> <div class="method-heading"> <span class="method-name">tag_multipart_encoding</span><span class="method-args">(filename, content_type, name, body)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="tag_multipart_encoding-source"> <pre><span class="ruby-comment"># File lib/rack/multipart/parser.rb, line 349</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">tag_multipart_encoding</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">content_type</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">body</span>) <span class="ruby-identifier">name</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-identifier">encoding</span> = <span class="ruby-constant">Encoding</span><span class="ruby-operator">::</span><span class="ruby-constant">UTF_8</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-identifier">encoding</span>) <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">content_type</span> <span class="ruby-identifier">list</span> = <span class="ruby-identifier">content_type</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">';'</span>) <span class="ruby-identifier">type_subtype</span> = <span class="ruby-identifier">list</span>.<span class="ruby-identifier">first</span> <span class="ruby-identifier">type_subtype</span>.<span class="ruby-identifier">strip!</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">TEXT_PLAIN</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">type_subtype</span> <span class="ruby-identifier">rest</span> = <span class="ruby-identifier">list</span>.<span class="ruby-identifier">drop</span> <span class="ruby-value">1</span> <span class="ruby-identifier">rest</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">param</span><span class="ruby-operator">|</span> <span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span> = <span class="ruby-identifier">param</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'='</span>, <span class="ruby-value">2</span>) <span class="ruby-identifier">k</span>.<span class="ruby-identifier">strip!</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">strip!</span> <span class="ruby-identifier">v</span> = <span class="ruby-identifier">v</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">'"'</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">end_with?</span>(<span class="ruby-string">'"'</span>) <span class="ruby-identifier">encoding</span> = <span class="ruby-constant">Encoding</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">v</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-constant">CHARSET</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-identifier">encoding</span>) <span class="ruby-identifier">body</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-identifier">encoding</span>) <span class="ruby-keyword">end</span></pre> </div> </div> </div> </section> </section> </main> <footer id="validator-badges" role="contentinfo"> <p><a href="https://validator.w3.org/check/referer">Validate</a> <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1. <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>. </footer>