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.header;
014
015import java.net.*;
016import java.util.function.*;
017
018import org.apache.juneau.http.annotation.*;
019
020/**
021 * Represents a parsed <l>Location</l> HTTP response header.
022 *
023 * <p>
024 * Used in redirection, or when a new resource has been created.
025 *
026 * <h5 class='figure'>Example</h5>
027 * <p class='bcode'>
028 *    Location: http://www.w3.org/pub/WWW/People.html
029 * </p>
030 *
031 * <h5 class='topic'>RFC2616 Specification</h5>
032 *
033 * The Location response-header field is used to redirect the recipient to a location other than the Request-URI for
034 * completion of the request or identification of a new resource.
035 * For 201 (Created) responses, the Location is that of the new resource which was created by the request.
036 * For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource.
037 * The field value consists of a single absolute URI.
038 *
039 * <p class='bcode'>
040 *    Location       = "Location" ":" absoluteURI
041 * </p>
042 *
043 * <p>
044 * An example is:
045 * <p class='bcode'>
046 *    Location: http://www.w3.org/pub/WWW/People.html
047 * </p>
048 *
049 * <p>
050 * Note: The Content-Location header field (section 14.14) differs from Location in that the Content-Location identifies
051 * the original location of the entity enclosed in the request.
052 * It is therefore possible for a response to contain header fields for both Location and Content-Location.
053 * Also see section 13.10 for cache requirements of some methods.
054 *
055 * <h5 class='section'>See Also:</h5><ul>
056 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
057 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
058 * </ul>
059 *
060 * @serial exclude
061 */
062@Header("Location")
063public class Location extends BasicUriHeader {
064
065   //-----------------------------------------------------------------------------------------------------------------
066   // Static
067   //-----------------------------------------------------------------------------------------------------------------
068
069   private static final long serialVersionUID = 1L;
070   private static final String NAME = "Location";
071
072   /**
073    * Static creator.
074    *
075    * @param value
076    *    The header value.
077    *    <br>Must be parsable by {@link URI#create(String)}.
078    *    <br>Can be <jk>null</jk>.
079    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
080    */
081   public static Location of(String value) {
082      return value == null ? null : new Location(value);
083   }
084
085   /**
086    * Static creator.
087    *
088    * @param value
089    *    The header value.
090    *    <br>Can be <jk>null</jk>.
091    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
092    */
093   public static Location of(URI value) {
094      return value == null ? null : new Location(value);
095   }
096
097   /**
098    * Static creator with delayed value.
099    *
100    * <p>
101    * Header value is re-evaluated on each call to {@link #getValue()}.
102    *
103    * @param value
104    *    The supplier of the header value.
105    *    <br>Can be <jk>null</jk>.
106    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
107    */
108   public static Location of(Supplier<URI> value) {
109      return value == null ? null : new Location(value);
110   }
111
112   //-----------------------------------------------------------------------------------------------------------------
113   // Instance
114   //-----------------------------------------------------------------------------------------------------------------
115
116   /**
117    * Constructor.
118    *
119    * @param value
120    *    The header value.
121    *    <br>Must be parsable by {@link URI#create(String)}.
122    *    <br>Can be <jk>null</jk>.
123    */
124   public Location(String value) {
125      super(NAME, value);
126   }
127
128   /**
129    * Constructor.
130    *
131    * @param value
132    *    The header value.
133    *    <br>Can be <jk>null</jk>.
134    */
135   public Location(URI value) {
136      super(NAME, value);
137   }
138
139   /**
140    * Constructor with delayed value.
141    *
142    * <p>
143    * Header value is re-evaluated on each call to {@link #getValue()}.
144    *
145    * @param value
146    *    The supplier of the header value.
147    *    <br>Can be <jk>null</jk>.
148    */
149   public Location(Supplier<URI> value) {
150      super(NAME, value);
151   }
152}