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