001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http;
014
015/**
016 * Represents a parsed <l>Host</l> HTTP request header.
017 * 
018 * <p>
019 * The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening.
020 * The port number may be omitted if the port is the standard port for the service requested.
021 * Mandatory since HTTP/1.1.
022 * 
023 * <h5 class='figure'>Example</h5>
024 * <p class='bcode'>
025 *    Host: en.wikipedia.org:8080
026 *    Host: en.wikipedia.org
027 * </p>
028 * 
029 * <h5 class='topic'>RFC2616 Specification</h5>
030 * 
031 * The Host request-header field specifies the Internet host and port number of the resource being requested, as
032 * obtained from the original URI given by the user or referring resource (generally an HTTP URL, as described in
033 * section 3.2.2).
034 * The Host field value MUST represent the naming authority of the origin server or gateway given by the original URL.
035 * This allows the origin server or gateway to differentiate between internally-ambiguous URLs, such as the root "/" URL
036 * of a server for multiple host names on a single IP address.
037 * 
038 * <p class='bcode'>
039 *    Host = "Host" ":" host [ ":" port ] ; Section 3.2.2
040 * </p>
041 * 
042 * <p>
043 * A "host" without any trailing port information implies the default port for the service requested (e.g., "80" for an
044 * HTTP URL).
045 * For example, a request on the origin server for &lt;http://www.w3.org/pub/WWW/&gt; would properly include:
046 * <p class='bcode'>
047 *    GET /pub/WWW/ HTTP/1.1
048 *    Host: www.w3.org
049 * </p>
050 * 
051 * <p>
052 * A client MUST include a Host header field in all HTTP/1.1 request messages.
053 * If the requested URI does not include an Internet host name for the service being requested, then the Host header
054 * field MUST be given with an empty value.
055 * An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that
056 * identifies the service being requested by the proxy.
057 * All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request
058 * message which lacks a Host header field.
059 * 
060 * <p>
061 * See sections 5.2 and 19.6.1.1 for other requirements relating to Host.
062 * 
063 * <h5 class='section'>See Also:</h5>
064 * <ul class='doctree'>
065 *    <li class='extlink'><a class='doclink' href='https://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a>
066 * </ul>
067 */
068public final class Host extends HeaderString {
069
070   /**
071    * Returns a parsed <code>Host</code> header.
072    * 
073    * @param value The <code>Host</code> header string.
074    * @return The parsed <code>Host</code> header, or <jk>null</jk> if the string was null.
075    */
076   public static Host forString(String value) {
077      if (value == null)
078         return null;
079      return new Host(value);
080   }
081
082   private Host(String value) {
083      super(value);
084   }
085}