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