File: C:/Ruby27-x64/share/doc/ruby/html/URI/HTTP.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class URI::HTTP - RDoc 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"><a href="Generic.html">URI::Generic</a>
</div>
<div id="includes-section" class="nav-section">
<h3>Included Modules</h3>
<ul class="link-list">
<li><a class="include" href="../OpenURI/OpenRead.html">OpenURI::OpenRead</a>
</ul>
</div>
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li class="calls-super" ><a href="#method-c-build">::build</a>
<li ><a href="#method-i-request_uri">#request_uri</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="class-URI::HTTP">
<h1 id="class-URI::HTTP" class="class">
class URI::HTTP
</h1>
<section class="description">
<p>The syntax of <a href="HTTP.html"><code>HTTP</code></a> URIs is defined in RFC1738 section 3.3.</p>
<p>Note that the Ruby <a href="../URI.html"><code>URI</code></a> library allows <a href="HTTP.html"><code>HTTP</code></a> URLs containing usernames and passwords. This is not legal as per the RFC, but used to be supported in Internet Explorer 5 and 6, before the MS04-004 security update. See <URL:<a href="http://support.microsoft.com/kb/834489">support.microsoft.com/kb/834489</a>>.</p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section class="constants-list">
<header>
<h3>Constants</h3>
</header>
<dl>
<dt id="COMPONENT">COMPONENT
<dd><p>An <a href="../Array.html"><code>Array</code></a> of the available components for <a href="HTTP.html"><code>URI::HTTP</code></a>.</p>
<dt id="DEFAULT_PORT">DEFAULT_PORT
<dd><p>A Default port of 80 for <a href="HTTP.html"><code>URI::HTTP</code></a>.</p>
</dl>
</section>
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-build" class="method-detail ">
<div class="method-heading">
<span class="method-name">build</span><span
class="method-args">(args)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<h2 id="method-c-build-label-Description">Description<span><a href="#method-c-build-label-Description">¶</a> <a href="#top">↑</a></span></h2>
<p>Creates a new <a href="HTTP.html"><code>URI::HTTP</code></a> object from components, with syntax checking.</p>
<p>The components accepted are userinfo, host, port, path, query, and fragment.</p>
<p>The components should be provided either as an <a href="../Array.html"><code>Array</code></a>, or as a <a href="../Hash.html"><code>Hash</code></a> with keys formed by preceding the component names with a colon.</p>
<p>If an <a href="../Array.html"><code>Array</code></a> is used, the components must be passed in the order <code>[userinfo, host, port, path, query, fragment]</code>.</p>
<p>Example:</p>
<pre class="ruby"><span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">build</span>(<span class="ruby-value">host:</span> <span class="ruby-string">'www.example.com'</span>, <span class="ruby-value">path:</span> <span class="ruby-string">'/foo/bar'</span>)
<span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">build</span>([<span class="ruby-keyword">nil</span>, <span class="ruby-string">"www.example.com"</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">"/path"</span>,
<span class="ruby-string">"query"</span>, <span class="ruby-string">'fragment'</span>])
</pre>
<p>Currently, if passed userinfo components this method generates invalid <a href="HTTP.html"><code>HTTP</code></a> URIs as per RFC 1738.</p>
<div class="method-calls-super">
Calls superclass method
<a href="Generic.html#method-c-build"><code>URI::Generic::build</code></a>
</div>
<div class="method-source-code" id="build-source">
<pre><span class="ruby-comment"># File lib/uri/http.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">build</span>(<span class="ruby-identifier">args</span>)
<span class="ruby-identifier">tmp</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">make_components_hash</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">args</span>)
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">tmp</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-request_uri" class="method-detail ">
<div class="method-heading">
<span class="method-name">request_uri</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<h2 id="method-i-request_uri-label-Description">Description<span><a href="#method-i-request_uri-label-Description">¶</a> <a href="#top">↑</a></span></h2>
<p>Returns the full path for an <a href="HTTP.html"><code>HTTP</code></a> request, as required by <a href="../Net/HTTP/Get.html"><code>Net::HTTP::Get</code></a>.</p>
<p>If the <a href="../URI.html"><code>URI</code></a> contains a query, the full path is URI#path + '?' + URI#query. Otherwise, the path is simply URI#path.</p>
<p>Example:</p>
<pre class="ruby"><span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">build</span>(<span class="ruby-value">path:</span> <span class="ruby-string">'/foo/bar'</span>, <span class="ruby-value">query:</span> <span class="ruby-string">'test=true'</span>)
<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">request_uri</span> <span class="ruby-comment"># => "/foo/bar?test=true"</span>
</pre>
<div class="method-source-code" id="request_uri-source">
<pre><span class="ruby-comment"># File lib/uri/http.rb, line 78</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">request_uri</span>
<span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@path</span>
<span class="ruby-identifier">url</span> = <span class="ruby-ivar">@query</span> <span class="ruby-operator">?</span> <span class="ruby-string">"#@path?#@query"</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@path</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-identifier">url</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-value">?/</span>.<span class="ruby-identifier">freeze</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">url</span> <span class="ruby-operator">:</span> <span class="ruby-value">?/</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">url</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>