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