LCOV - code coverage report
Current view: directory - netwerk/protocol/http - nsHttpResponseHead.h (source / functions) Found Hit Coverage
Test: app.info Lines: 25 24 96.0 %
Date: 2012-06-02 Functions: 21 20 95.2 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Darin Fisher <darin@netscape.com> (original author)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsHttpResponseHead_h__
      40                 : #define nsHttpResponseHead_h__
      41                 : 
      42                 : #include "nsHttpHeaderArray.h"
      43                 : #include "nsHttp.h"
      44                 : #include "nsString.h"
      45                 : 
      46                 : //-----------------------------------------------------------------------------
      47                 : // nsHttpResponseHead represents the status line and headers from an HTTP
      48                 : // response.
      49                 : //-----------------------------------------------------------------------------
      50                 : 
      51                 : class nsHttpResponseHead
      52               0 : {
      53                 : public:
      54            3397 :     nsHttpResponseHead() : mVersion(NS_HTTP_VERSION_1_1)
      55                 :                          , mStatus(200)
      56                 :                          , mContentLength(LL_MAXUINT)
      57                 :                          , mCacheControlNoStore(false)
      58                 :                          , mCacheControlNoCache(false)
      59            3397 :                          , mPragmaNoCache(false) {}
      60            3397 :     ~nsHttpResponseHead() 
      61            3397 :     {
      62            3397 :         Reset();
      63            3397 :     }
      64                 :     
      65            1394 :     nsHttpHeaderArray    &Headers()        { return mHeaders; }
      66            9331 :     nsHttpVersion         Version()        { return mVersion; }
      67           23671 :     PRUint16              Status()         { return mStatus; }
      68              99 :     const nsAFlatCString &StatusText()     { return mStatusText; }
      69            9717 :     PRInt64               ContentLength()  { return mContentLength; }
      70           11437 :     const nsAFlatCString &ContentType()    { return mContentType; }
      71            3861 :     const nsAFlatCString &ContentCharset() { return mContentCharset; }
      72            4383 :     bool                  NoStore()        { return mCacheControlNoStore; }
      73            1139 :     bool                  NoCache()        { return (mCacheControlNoCache || mPragmaNoCache); }
      74                 :     /**
      75                 :      * Full length of the entity. For byte-range requests, this may be larger
      76                 :      * than ContentLength(), which will only represent the requested part of the
      77                 :      * entity.
      78                 :      */
      79                 :     PRInt64               TotalEntitySize();
      80                 : 
      81           18740 :     const char *PeekHeader(nsHttpAtom h)            { return mHeaders.PeekHeader(h); }
      82                 :     nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false);
      83           12345 :     nsresult GetHeader(nsHttpAtom h, nsACString &v) { return mHeaders.GetHeader(h, v); }
      84               2 :     void     ClearHeader(nsHttpAtom h)              { mHeaders.ClearHeader(h); }
      85            3397 :     void     ClearHeaders()                         { mHeaders.Clear(); }
      86                 : 
      87                 :     const char *FindHeaderValue(nsHttpAtom h, const char *v) { return mHeaders.FindHeaderValue(h, v); }
      88            8129 :     bool        HasHeaderValue(nsHttpAtom h, const char *v) { return mHeaders.HasHeaderValue(h, v); }
      89                 : 
      90            1408 :     void     SetContentType(const nsACString &s)    { mContentType = s; }
      91            2878 :     void     SetContentCharset(const nsACString &s) { mContentCharset = s; }
      92                 :     void     SetContentLength(PRInt64);
      93                 : 
      94                 :     // write out the response status line and headers as a single text block,
      95                 :     // optionally pruning out transient headers (ie. headers that only make
      96                 :     // sense the first time the response is handled).
      97                 :     void     Flatten(nsACString &, bool pruneTransients);
      98                 : 
      99                 :     // parse flattened response head. block must be null terminated. parsing is
     100                 :     // destructive.
     101                 :     nsresult Parse(char *block);
     102                 : 
     103                 :     // parse the status line. line must be null terminated.
     104                 :     void     ParseStatusLine(const char *line);
     105                 : 
     106                 :     // parse a header line. line must be null terminated. parsing is destructive.
     107                 :     nsresult ParseHeaderLine(const char *line);
     108                 : 
     109                 :     // cache validation support methods
     110                 :     nsresult ComputeFreshnessLifetime(PRUint32 *);
     111                 :     nsresult ComputeCurrentAge(PRUint32 now, PRUint32 requestTime, PRUint32 *result);
     112                 :     bool     MustValidate();
     113                 :     bool     MustValidateIfExpired();
     114                 : 
     115                 :     // returns true if the server appears to support byte range requests.
     116                 :     bool     IsResumable();
     117                 : 
     118                 :     // returns true if the Expires header has a value in the past relative to the
     119                 :     // value of the Date header.
     120                 :     bool     ExpiresInPast();
     121                 : 
     122                 :     // update headers...
     123                 :     nsresult UpdateHeaders(nsHttpHeaderArray &headers); 
     124                 : 
     125                 :     // reset the response head to it's initial state
     126                 :     void     Reset();
     127                 : 
     128                 :     // these return failure if the header does not exist.
     129                 :     nsresult ParseDateHeader(nsHttpAtom header, PRUint32 *result);
     130                 :     nsresult GetAgeValue(PRUint32 *result);
     131                 :     nsresult GetMaxAgeValue(PRUint32 *result);
     132            1429 :     nsresult GetDateValue(PRUint32 *result)         { return ParseDateHeader(nsHttp::Date, result); }
     133                 :     nsresult GetExpiresValue(PRUint32 *result);
     134             799 :     nsresult GetLastModifiedValue(PRUint32 *result) { return ParseDateHeader(nsHttp::Last_Modified, result); }
     135                 : 
     136                 : private:
     137                 :     void     ParseVersion(const char *);
     138                 :     void     ParseCacheControl(const char *);
     139                 :     void     ParsePragma(const char *);
     140                 : 
     141                 : private:
     142                 :     nsHttpHeaderArray mHeaders;
     143                 :     nsHttpVersion     mVersion;
     144                 :     PRUint16          mStatus;
     145                 :     nsCString         mStatusText;
     146                 :     PRInt64           mContentLength;
     147                 :     nsCString         mContentType;
     148                 :     nsCString         mContentCharset;
     149                 :     bool              mCacheControlNoStore;
     150                 :     bool              mCacheControlNoCache;
     151                 :     bool              mPragmaNoCache;
     152                 : 
     153                 :     friend struct IPC::ParamTraits<nsHttpResponseHead>;
     154                 : };
     155                 : 
     156                 : #endif // nsHttpResponseHead_h__

Generated by: LCOV version 1.7