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-Length</l> HTTP request/response header. 017 * 018 * <p> 019 * The length of the response body in octets (8-bit bytes). 020 * 021 * <h5 class='figure'>Example</h5> 022 * <p class='bcode'> 023 * Content-Length: 348 024 * </p> 025 * 026 * <h5 class='topic'>RFC2616 Specification</h5> 027 * 028 * The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to 029 * the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the 030 * request been a GET. 031 * <p class='bcode'> 032 * Content-Length = "Content-Length" ":" 1*DIGIT 033 * </p> 034 * 035 * <p> 036 * An example is... 037 * <p class='bcode'> 038 * Content-Length: 3495 039 * </p> 040 * 041 * <p> 042 * Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by 043 * the rules in section 4.4. 044 * 045 * <p> 046 * Any Content-Length greater than or equal to zero is a valid value. 047 * Section 4.4 describes how to determine the length of a message-body if a Content-Length is not given. 048 * 049 * <p> 050 * Note that the meaning of this field is significantly different from the corresponding definition in MIME, where it is 051 * an optional field used within the "message/external-body" content-type. 052 * In HTTP, it SHOULD be sent whenever the message's length can be determined prior to being transferred, unless this is 053 * prohibited by the rules in section 4.4. 054 * 055 * <h5 class='section'>See Also:</h5> 056 * <ul class='doctree'> 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 */ 060public final class ContentLength extends HeaderInteger { 061 062 /** 063 * Returns a parsed <code>Content-Length</code> header. 064 * 065 * @param value The <code>Content-Length</code> header string. 066 * @return The parsed <code>Content-Length</code> header, or <jk>null</jk> if the string was null. 067 */ 068 public static ContentLength forString(String value) { 069 if (value == null) 070 return null; 071 return new ContentLength(value); 072 } 073 074 private ContentLength(String value) { 075 super(value); 076 } 077}