~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/http/public/http_value.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 Google Inc.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
// Author: jmarantz@google.com (Joshua Marantz)
18
 
 
19
 
#ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
20
 
#define NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
21
 
 
22
 
#include <cstddef>                     // for size_t
23
 
#include "net/instaweb/util/public/basictypes.h"
24
 
#include "net/instaweb/util/public/shared_string.h"
25
 
#include "net/instaweb/util/public/string_util.h"
26
 
#include "net/instaweb/util/public/writer.h"
27
 
 
28
 
namespace net_instaweb {
29
 
 
30
 
class ResponseHeaders;
31
 
class MessageHandler;
32
 
 
33
 
// Provides shared, ref-counted, copy-on-write storage for HTTP
34
 
// contents, to aid sharing between active fetches and filters, and
35
 
// the cache, which from which data may be evicted at any time.
36
 
class HTTPValue : public Writer {
37
 
 public:
38
 
  HTTPValue() : contents_size_(0) {}
39
 
 
40
 
  // Clears the value (both headers and content)
41
 
  void Clear();
42
 
 
43
 
  // Is this HTTPValue empty
44
 
  bool Empty() const { return storage_.empty(); }
45
 
 
46
 
  // Sets the HTTP headers for this value. This method may only
47
 
  // be called once and must be called before or after all of the
48
 
  // contents are set (using the streaming interface Write).
49
 
  //
50
 
  // If Clear() is called, then SetHeaders() can be called once again.
51
 
  //
52
 
  // Does NOT take ownership of headers.
53
 
  // A non-const pointer is required for the response headers so that
54
 
  // the cache fields can be updated if necessary.
55
 
  void SetHeaders(ResponseHeaders* headers);
56
 
 
57
 
  // Writes contents into the HTTPValue object.  Write can be called
58
 
  // multiple times to append more data, and can be called before
59
 
  // or after SetHeaders.  However, SetHeaders cannot be interleaved
60
 
  // in between calls to Write.
61
 
  virtual bool Write(const StringPiece& str, MessageHandler* handler);
62
 
  virtual bool Flush(MessageHandler* handler);
63
 
 
64
 
  // Retrieves the headers, returning false if empty.
65
 
  bool ExtractHeaders(ResponseHeaders* headers, MessageHandler* handler) const;
66
 
 
67
 
  // Retrieves the contents, returning false if empty.  Note that the
68
 
  // contents are only guaranteed valid as long as the HTTPValue
69
 
  // object is in scope.
70
 
  bool ExtractContents(StringPiece* str) const;
71
 
 
72
 
  // Tests whether this reference is the only active one to the string object.
73
 
  bool unique() const { return storage_.unique(); }
74
 
 
75
 
  // Assigns the storage of an HTTPValue based on the provided storage.  This
76
 
  // can be used for a cache Get.  Returns false if the string is not
77
 
  // well-formed.
78
 
  //
79
 
  // Extracts the headers into the provided ResponseHeaders buffer.
80
 
  bool Link(SharedString* src, ResponseHeaders* headers,
81
 
            MessageHandler* handler);
82
 
 
83
 
  // Links two HTTPValues together, using the contents of 'src' and discarding
84
 
  // the contents of this.
85
 
  void Link(HTTPValue* src) {
86
 
    if (src != this) {
87
 
      storage_ = src->storage_;  // SharedString links via assignment.
88
 
      contents_size_ = src->contents_size();
89
 
    }
90
 
  }
91
 
 
92
 
  // Access the shared string, for insertion into a cache via Put.
93
 
  SharedString* share() { return &storage_; }
94
 
 
95
 
  size_t size() const { return storage_.size(); }
96
 
  int64 contents_size() { return contents_size_; }
97
 
 
98
 
 private:
99
 
  friend class HTTPValueTest;
100
 
 
101
 
  // Must be called with storage_ non-empty.
102
 
  char type_identifier() const { return *storage_.data(); }
103
 
 
104
 
  unsigned int SizeOfFirstChunk() const;
105
 
  void SetSizeOfFirstChunk(unsigned int size);
106
 
  int64 ComputeContentsSize() const;
107
 
 
108
 
  // Disconnects this HTTPValue from other HTTPValues that may share the
109
 
  // underlying storage, allowing a new buffer.
110
 
  void CopyOnWrite();
111
 
 
112
 
  SharedString storage_;
113
 
  // Member variable to keep the size of body in storage.
114
 
  int64 contents_size_;
115
 
 
116
 
  DISALLOW_COPY_AND_ASSIGN(HTTPValue);
117
 
};
118
 
 
119
 
}  // namespace net_instaweb
120
 
 
121
 
#endif  // NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_