001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.header; 018 019import java.util.function.*; 020 021import org.apache.juneau.http.annotation.*; 022 023/** 024 * Represents a parsed <l>Host</l> HTTP request header. 025 * 026 * <p> 027 * The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. 028 * The port number may be omitted if the port is the standard port for the service requested. 029 * Mandatory since HTTP/1.1. 030 * 031 * <h5 class='figure'>Example</h5> 032 * <p class='bcode'> 033 * Host: en.wikipedia.org:8080 034 * Host: en.wikipedia.org 035 * </p> 036 * 037 * <h5 class='topic'>RFC2616 Specification</h5> 038 * 039 * The Host request-header field specifies the Internet host and port number of the resource being requested, as 040 * obtained from the original URI given by the user or referring resource (generally an HTTP URL, as described in 041 * section 3.2.2). 042 * The Host field value MUST represent the naming authority of the origin server or gateway given by the original URL. 043 * This allows the origin server or gateway to differentiate between internally-ambiguous URLs, such as the root "/" URL 044 * of a server for multiple host names on a single IP address. 045 * 046 * <p class='bcode'> 047 * Host = "Host" ":" host [ ":" port ] ; Section 3.2.2 048 * </p> 049 * 050 * <p> 051 * A "host" without any trailing port information implies the default port for the service requested (e.g., "80" for an 052 * HTTP URL). 053 * For example, a request on the origin server for <http://www.w3.org/pub/WWW/> would properly include: 054 * <p class='bcode'> 055 * GET /pub/WWW/ HTTP/1.1 056 * Host: www.w3.org 057 * </p> 058 * 059 * <p> 060 * A client MUST include a Host header field in all HTTP/1.1 request messages. 061 * If the requested URI does not include an Internet host name for the service being requested, then the Host header 062 * field MUST be given with an empty value. 063 * An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that 064 * identifies the service being requested by the proxy. 065 * All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request 066 * message which lacks a Host header field. 067 * 068 * <p> 069 * See sections 5.2 and 19.6.1.1 for other requirements relating to Host. 070 * 071 * <h5 class='section'>See Also:</h5><ul> 072 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 073 * <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a> 074 * </ul> 075 * 076 * @serial exclude 077 */ 078@Header("Host") 079public class Host extends BasicStringHeader { 080 081 //----------------------------------------------------------------------------------------------------------------- 082 // Static 083 //----------------------------------------------------------------------------------------------------------------- 084 085 private static final long serialVersionUID = 1L; 086 private static final String NAME = "Host"; 087 088 /** 089 * Static creator. 090 * 091 * @param value 092 * The header value. 093 * <br>Can be <jk>null</jk>. 094 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 095 */ 096 public static Host of(String value) { 097 return value == null ? null : new Host(value); 098 } 099 100 /** 101 * Static creator with delayed value. 102 * 103 * <p> 104 * Header value is re-evaluated on each call to {@link #getValue()}. 105 * 106 * @param value 107 * The supplier of the header value. 108 * <br>Can be <jk>null</jk>. 109 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 110 */ 111 public static Host of(Supplier<String> value) { 112 return value == null ? null : new Host(value); 113 } 114 115 //----------------------------------------------------------------------------------------------------------------- 116 // Instance 117 //----------------------------------------------------------------------------------------------------------------- 118 119 /** 120 * Constructor. 121 * 122 * @param value 123 * The header value. 124 * <br>Can be <jk>null</jk>. 125 */ 126 public Host(String value) { 127 super(NAME, value); 128 } 129 130 /** 131 * Constructor with delayed value. 132 * 133 * <p> 134 * Header value is re-evaluated on each call to {@link #getValue()}. 135 * 136 * @param value 137 * The supplier of the header value. 138 * <br>Can be <jk>null</jk>. 139 */ 140 public Host(Supplier<String> value) { 141 super(NAME, value); 142 } 143}