doc/rdoc/classes/RFuzz/HttpClient.src/M000026.html in rfuzz-0.8 vs doc/rdoc/classes/RFuzz/HttpClient.src/M000026.html in rfuzz-0.9
- old
+ new
@@ -3,36 +3,42 @@
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
- <title>send_request (RFuzz::HttpClient)</title>
+ <title>read_response (RFuzz::HttpClient)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre> <span class="ruby-comment cmt"># File lib/rfuzz/client.rb, line 376</span>
-376: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_request</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">req</span>)
-377: <span class="ruby-keyword kw">begin</span>
-378: <span class="ruby-identifier">notify</span> <span class="ruby-identifier">:connect</span> <span class="ruby-keyword kw">do</span>
-379: <span class="ruby-ivar">@sock</span> = <span class="ruby-constant">PushBackIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@port</span>))
-380: <span class="ruby-keyword kw">end</span>
-381:
-382: <span class="ruby-identifier">out</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
-383: <span class="ruby-identifier">body</span> = <span class="ruby-identifier">build_request</span>(<span class="ruby-identifier">out</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">req</span>)
-384:
-385: <span class="ruby-identifier">notify</span> <span class="ruby-identifier">:send_request</span> <span class="ruby-keyword kw">do</span>
-386: <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">out</span>.<span class="ruby-identifier">string</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">body</span>)
-387: <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">flush</span>
-388: <span class="ruby-keyword kw">end</span>
-389:
-390: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read_response</span>
-391: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Object</span>
-392: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">$!</span>
-393: <span class="ruby-keyword kw">ensure</span>
-394: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@sock</span>
-395: <span class="ruby-identifier">notify</span>(<span class="ruby-identifier">:close</span>) { <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">close</span> }
-396: <span class="ruby-keyword kw">end</span>
-397: <span class="ruby-keyword kw">end</span>
-398: <span class="ruby-keyword kw">end</span></pre>
+ <pre> <span class="ruby-comment cmt"># File lib/rfuzz/client.rb, line 344</span>
+344: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_response</span>
+345: <span class="ruby-identifier">resp</span> = <span class="ruby-constant">HttpResponse</span>.<span class="ruby-identifier">new</span>
+346:
+347: <span class="ruby-identifier">notify</span> <span class="ruby-identifier">:read_header</span> <span class="ruby-keyword kw">do</span>
+348: <span class="ruby-identifier">resp</span> = <span class="ruby-identifier">read_parsed_header</span>
+349: <span class="ruby-keyword kw">end</span>
+350:
+351: <span class="ruby-identifier">notify</span> <span class="ruby-identifier">:read_body</span> <span class="ruby-keyword kw">do</span>
+352: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">chunked_encoding?</span>
+353: <span class="ruby-identifier">read_chunked_body</span>(<span class="ruby-identifier">resp</span>)
+354: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">resp</span>[<span class="ruby-constant">CONTENT_LENGTH</span>]
+355: <span class="ruby-identifier">needs</span> = <span class="ruby-identifier">resp</span>[<span class="ruby-constant">CONTENT_LENGTH</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">http_body</span>.<span class="ruby-identifier">length</span>
+356: <span class="ruby-comment cmt"># Some requests can actually give a content length, and then not have content</span>
+357: <span class="ruby-comment cmt"># so we ignore HttpClientError exceptions and pray that's good enough</span>
+358: <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">http_body</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">needs</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">needs</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">HttpClientError</span>
+359: <span class="ruby-keyword kw">else</span>
+360: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
+361: <span class="ruby-keyword kw">begin</span>
+362: <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">http_body</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">read</span>(<span class="ruby-constant">CHUNK_SIZE</span>, <span class="ruby-identifier">partial</span>=<span class="ruby-keyword kw">true</span>)
+363: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">HttpClientError</span>
+364: <span class="ruby-keyword kw">break</span> <span class="ruby-comment cmt"># this is fine, they closed the socket then</span>
+365: <span class="ruby-keyword kw">end</span>
+366: <span class="ruby-keyword kw">end</span>
+367: <span class="ruby-keyword kw">end</span>
+368: <span class="ruby-keyword kw">end</span>
+369:
+370: <span class="ruby-identifier">store_cookies</span>(<span class="ruby-identifier">resp</span>)
+371: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">resp</span>
+372: <span class="ruby-keyword kw">end</span></pre>
</body>
</html>
\ No newline at end of file