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.util.function.*;
016
017import org.apache.juneau.http.annotation.*;
018
019/**
020 * Represents a parsed <l>Accept-Range</l> HTTP response header.
021 *
022 * <p>
023 * What partial content range types this server supports via byte serving.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode'>
027 *    Accept-Ranges: bytes
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The Accept-Ranges response-header field allows the server to indicate its acceptance of range requests for a
033 * resource:
034 * <p class='bcode'>
035 *    Accept-Ranges     = "Accept-Ranges" ":" acceptable-ranges
036 *    acceptable-ranges = 1#range-unit | "none"
037 * </p>
038 *
039 * <p>
040 * Origin servers that accept byte-range requests MAY send...
041 * <p class='bcode'>
042 *    Accept-Ranges: bytes
043 * </p>
044 * <p>
045 * ...but are not required to do so.
046 *
047 * <p>
048 * Clients MAY generate byte-range requests without having received this header for the resource involved.
049 *
050 * <p>
051 * Range units are defined in section 3.12.
052 *
053 * <p>
054 * Servers that do not accept any kind of range request for a resource MAY send...
055 * <p class='bcode'>
056 *    Accept-Ranges: none
057 * </p>
058 * <p>
059 * ...to advise the client not to attempt a range request.
060 *
061 * <h5 class='section'>See Also:</h5><ul>
062 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
063 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
064 * </ul>
065 *
066 * @serial exclude
067 */
068@Header("Accept-Ranges")
069public class AcceptRanges extends BasicStringHeader {
070
071   //-----------------------------------------------------------------------------------------------------------------
072   // Static
073   //-----------------------------------------------------------------------------------------------------------------
074
075   private static final long serialVersionUID = 1L;
076   private static final String NAME = "Accept-Ranges";
077
078   /**
079    * Static creator.
080    *
081    * @param value
082    *    The header value.
083    *    <br>Can be <jk>null</jk>.
084    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
085    */
086   public static AcceptRanges of(String value) {
087      return value == null ? null : new AcceptRanges(value);
088   }
089
090   /**
091    * Static creator with delayed value.
092    *
093    * <p>
094    * Header value is re-evaluated on each call to {@link #getValue()}.
095    *
096    * @param value
097    *    The supplier of the header value.
098    *    <br>Can be <jk>null</jk>.
099    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
100    */
101   public static AcceptRanges of(Supplier<String> value) {
102      return value == null ? null : new AcceptRanges(value);
103   }
104
105   //-----------------------------------------------------------------------------------------------------------------
106   // Instance
107   //-----------------------------------------------------------------------------------------------------------------
108
109   /**
110    * Constructor.
111    *
112    * @param value
113    *    The header value.
114    *    <br>Can be <jk>null</jk>.
115    */
116   public AcceptRanges(String value) {
117      super(NAME, value);
118   }
119
120   /**
121    * Constructor with delayed value.
122    *
123    * <p>
124    * Header value is re-evaluated on each call to {@link #getValue()}.
125    *
126    * @param value
127    *    The supplier of the header value.
128    *    <br>Can be <jk>null</jk>.
129    */
130   public AcceptRanges(Supplier<String> value) {
131      super(NAME, value);
132   }
133}