File: M000083.html

package info (click to toggle)
wfo 0.1-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 1,508 kB
  • ctags: 485
  • sloc: ruby: 1,996; makefile: 66
file content (44 lines) | stat: -rw-r--r-- 3,785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>do_redirect_requests (WFO::WebClient)</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 wfo/webclient.rb, line 99</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_redirect_requests</span>(<span class="ruby-identifier">request</span>)
    <span class="ruby-identifier">results</span> = []
    <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
      <span class="ruby-identifier">response</span> = <span class="ruby-identifier">do_request_state</span>(<span class="ruby-identifier">request</span>)
      <span class="ruby-identifier">results</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">request</span>, <span class="ruby-identifier">response</span>]
      <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/\A(?:301|302|303|307)\z/</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">code</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">response</span>[<span class="ruby-value str">'location'</span>]
        <span class="ruby-comment cmt"># RFC 1945 - Hypertext Transfer Protocol -- HTTP/1.0</span>
        <span class="ruby-comment cmt">#  301 Moved Permanently</span>
        <span class="ruby-comment cmt">#  302 Moved Temporarily</span>
        <span class="ruby-comment cmt"># RFC 2068 - Hypertext Transfer Protocol -- HTTP/1.1</span>
        <span class="ruby-comment cmt">#  301 Moved Permanently</span>
        <span class="ruby-comment cmt">#  302 Moved Temporarily</span>
        <span class="ruby-comment cmt">#  303 See Other</span>
        <span class="ruby-comment cmt"># RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1</span>
        <span class="ruby-comment cmt">#  301 Moved Permanently</span>
        <span class="ruby-comment cmt">#  302 Found</span>
        <span class="ruby-comment cmt">#  303 See Other</span>
        <span class="ruby-comment cmt">#  307 Temporary Redirect</span>
        <span class="ruby-identifier">redirect</span> = <span class="ruby-constant">URI</span>(<span class="ruby-identifier">response</span>[<span class="ruby-value str">'location'</span>])
        <span class="ruby-comment cmt"># Although it violates RFC2616, Location: field may have relative</span>
        <span class="ruby-comment cmt"># URI.  It is converted to absolute URI using uri as a base URI.</span>
        <span class="ruby-identifier">redirect</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">uri</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">redirect</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">redirect</span>.<span class="ruby-identifier">relative?</span>
        <span class="ruby-identifier">request</span> = <span class="ruby-constant">WFO</span><span class="ruby-operator">::</span><span class="ruby-constant">ReqHTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">redirect</span>)
      <span class="ruby-keyword kw">else</span>
        <span class="ruby-keyword kw">break</span>
      <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">end</span>
    <span class="ruby-identifier">results</span>
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>