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 015import org.apache.juneau.http.annotation.*; 016 017/** 018 * Represents a parsed <l>Host</l> HTTP request header. 019 * 020 * <p> 021 * The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. 022 * The port number may be omitted if the port is the standard port for the service requested. 023 * Mandatory since HTTP/1.1. 024 * 025 * <h5 class='figure'>Example</h5> 026 * <p class='bcode w800'> 027 * Host: en.wikipedia.org:8080 028 * Host: en.wikipedia.org 029 * </p> 030 * 031 * <h5 class='topic'>RFC2616 Specification</h5> 032 * 033 * The Host request-header field specifies the Internet host and port number of the resource being requested, as 034 * obtained from the original URI given by the user or referring resource (generally an HTTP URL, as described in 035 * section 3.2.2). 036 * The Host field value MUST represent the naming authority of the origin server or gateway given by the original URL. 037 * This allows the origin server or gateway to differentiate between internally-ambiguous URLs, such as the root "/" URL 038 * of a server for multiple host names on a single IP address. 039 * 040 * <p class='bcode w800'> 041 * Host = "Host" ":" host [ ":" port ] ; Section 3.2.2 042 * </p> 043 * 044 * <p> 045 * A "host" without any trailing port information implies the default port for the service requested (e.g., "80" for an 046 * HTTP URL). 047 * For example, a request on the origin server for <http://www.w3.org/pub/WWW/> would properly include: 048 * <p class='bcode w800'> 049 * GET /pub/WWW/ HTTP/1.1 050 * Host: www.w3.org 051 * </p> 052 * 053 * <p> 054 * A client MUST include a Host header field in all HTTP/1.1 request messages. 055 * If the requested URI does not include an Internet host name for the service being requested, then the Host header 056 * field MUST be given with an empty value. 057 * An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that 058 * identifies the service being requested by the proxy. 059 * All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request 060 * message which lacks a Host header field. 061 * 062 * <p> 063 * See sections 5.2 and 19.6.1.1 for other requirements relating to Host. 064 * 065 * <h5 class='section'>See Also:</h5> 066 * <ul class='doctree'> 067 * <li class='extlink'>{@doc RFC2616} 068 * </ul> 069 */ 070@Header("Host") 071public final class Host extends HeaderString { 072 073 /** 074 * Returns a parsed <code>Host</code> header. 075 * 076 * @param value The <code>Host</code> header string. 077 * @return The parsed <code>Host</code> header, or <jk>null</jk> if the string was null. 078 */ 079 public static Host forString(String value) { 080 if (value == null) 081 return null; 082 return new Host(value); 083 } 084 085 private Host(String value) { 086 super(value); 087 } 088}