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>Content-Range</l> HTTP response header. 019 * 020 * <p> 021 * Where in a full body message this partial message belongs. 022 * 023 * <h5 class='figure'>Example</h5> 024 * <p class='bcode w800'> 025 * Content-Range: bytes 21010-47021/47022 026 * </p> 027 * 028 * <h5 class='topic'>RFC2616 Specification</h5> 029 * 030 * The Content-Range entity-header is sent with a partial entity-body to specify where in the full entity-body the 031 * partial body should be applied. 032 * Range units are defined in section 3.12. 033 * <p class='bcode w800'> 034 * Content-Range = "Content-Range" ":" content-range-spec 035 * content-range-spec = byte-content-range-spec 036 * byte-content-range-spec = bytes-unit SP 037 * byte-range-resp-spec "/" 038 * ( instance-length | "*" ) 039 * byte-range-resp-spec = (first-byte-pos "-" last-byte-pos) 040 * | "*" 041 * instance-length = 1*DIGIT 042 * </p> 043 * 044 * <p> 045 * The header SHOULD indicate the total length of the full entity-body, unless this length is unknown or difficult to 046 * determine. 047 * The asterisk "*" character means that the instance-length is unknown at the time when the response was generated. 048 * 049 * <p> 050 * Unlike byte-ranges-specifier values (see section 14.35.1), a byte- range-resp-spec MUST only specify one range, and 051 * MUST contain absolute byte positions for both the first and last byte of the range. 052 * 053 * <p> 054 * A byte-content-range-spec with a byte-range-resp-spec whose last- byte-pos value is less than its first-byte-pos 055 * value, or whose instance-length value is less than or equal to its last-byte-pos value, is invalid. 056 * The recipient of an invalid byte-content-range- spec MUST ignore it and any content transferred along with it. 057 * 058 * <p> 059 * A server sending a response with status code 416 (Requested range not satisfiable) SHOULD include a Content-Range 060 * field with a byte-range- resp-spec of "*". 061 * The instance-length specifies the current length of the selected resource. 062 * A response with status code 206 (Partial Content) MUST NOT include a Content-Range field with a byte-range-resp-spec 063 * of "*". 064 * 065 * <p> 066 * Examples of byte-content-range-spec values, assuming that the entity contains a total of 1234 bytes: 067 * <p class='bcode w800'> 068 * The first 500 bytes: 069 * bytes 0-499/1234 070 * The second 500 bytes: 071 * bytes 500-999/1234 072 * All except for the first 500 bytes: 073 * bytes 500-1233/1234 074 * The last 500 bytes: 075 * bytes 734-1233/1234 076 * </p> 077 * 078 * <p> 079 * When an HTTP message includes the content of a single range (for example, a response to a request for a single range, 080 * or to a request for a set of ranges that overlap without any holes), this content is transmitted with a Content-Range 081 * header, and a Content-Length header showing the number of bytes actually transferred. 082 * For example: 083 * <p class='bcode w800'> 084 * HTTP/1.1 206 Partial content 085 * Date: Wed, 15 Nov 1995 06:25:24 GMT 086 * Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT 087 * Content-Range: bytes 21010-47021/47022 088 * Content-Length: 26012 089 * Content-Type: image/gif 090 * </p> 091 * 092 * <p> 093 * When an HTTP message includes the content of multiple ranges (for example, a response to a request for multiple 094 * non-overlapping ranges), these are transmitted as a multipart message. 095 * The multipart media type used for this purpose is "multipart/byteranges" as defined in appendix 19.2. 096 * See appendix 19.6.3 for a compatibility issue. 097 * 098 * <p> 099 * A response to a request for a single range MUST NOT be sent using the multipart/byteranges media type. 100 * A response to a request for multiple ranges, whose result is a single range, MAY be sent as a multipart/byteranges 101 * media type with one part. 102 * A client that cannot decode a multipart/byteranges message MUST NOT ask for multiple byte-ranges in a single request. 103 * 104 * <p> 105 * When a client requests multiple byte-ranges in one request, the server SHOULD return them in the order that they 106 * appeared in the request. 107 * 108 * <p> 109 * If the server ignores a byte-range-spec because it is syntactically invalid, the server SHOULD treat the request as 110 * if the invalid Range header field did not exist. 111 * (Normally, this means return a 200 response containing the full entity). 112 * 113 * <p> 114 * If the server receives a request (other than one including an If- Range request-header field) with an unsatisfiable 115 * Range request- header field 116 * (that is, all of whose byte-range-spec values have a first-byte-pos value greater than the current length of the 117 * selected resource), 118 * it SHOULD return a response code of 416 (Requested range not satisfiable) (section 10.4.17). 119 * 120 * <p> 121 * Note: clients cannot depend on servers to send a 416 (Requested range not satisfiable) response instead of a 200 (OK) 122 * response for 123 * an unsatisfiable Range request-header, since not all servers implement this request-header. 124 * 125 * <h5 class='section'>See Also:</h5> 126 * <ul class='doctree'> 127 * <li class='extlink'>{@doc RFC2616} 128 * </ul> 129 */ 130@Header("Content-Range") 131public final class ContentRange extends HeaderString { 132 133 /** 134 * Returns a parsed <code>Content-Range</code> header. 135 * 136 * @param value The <code>Content-Range</code> header string. 137 * @return The parsed <code>Content-Range</code> header, or <jk>null</jk> if the string was null. 138 */ 139 public static ContentRange forString(String value) { 140 if (value == null) 141 return null; 142 return new ContentRange(value); 143 } 144 145 private ContentRange(String value) { 146 super(value); 147 } 148}