Page Speed Optimization Libraries  1.2.24.1
net/instaweb/http/public/http_value.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
00020 #define NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
00021 
00022 #include <cstddef>                     
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/shared_string.h"
00025 #include "net/instaweb/util/public/string_util.h"
00026 #include "net/instaweb/util/public/writer.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class ResponseHeaders;
00031 class MessageHandler;
00032 
00036 class HTTPValue : public Writer {
00037  public:
00038   HTTPValue() : contents_size_(0) {}
00039 
00041   void Clear();
00042 
00044   bool Empty() const { return storage_.empty(); }
00045 
00054   void SetHeaders(ResponseHeaders* headers);
00055 
00060   virtual bool Write(const StringPiece& str, MessageHandler* handler);
00061   virtual bool Flush(MessageHandler* handler);
00062 
00064   bool ExtractHeaders(ResponseHeaders* headers, MessageHandler* handler) const;
00065 
00069   bool ExtractContents(StringPiece* str) const;
00070 
00072   bool unique() const { return storage_.unique(); }
00073 
00079   bool Link(SharedString* src, ResponseHeaders* headers,
00080             MessageHandler* handler);
00081 
00084   void Link(HTTPValue* src) {
00085     if (src != this) {
00086       storage_ = src->storage_; 
00087       contents_size_ = src->contents_size();
00088     }
00089   }
00090 
00092   SharedString* share() { return &storage_; }
00093 
00094   size_t size() const { return storage_.size(); }
00095   int64 contents_size() { return contents_size_; }
00096 
00097  private:
00098   friend class HTTPValueTest;
00099 
00101   char type_identifier() const { return *storage_.data(); }
00102 
00103   unsigned int SizeOfFirstChunk() const;
00104   void SetSizeOfFirstChunk(unsigned int size);
00105   int64 ComputeContentsSize() const;
00106 
00109   void CopyOnWrite();
00110 
00111   SharedString storage_;
00113   int64 contents_size_;
00114 
00115   DISALLOW_COPY_AND_ASSIGN(HTTPValue);
00116 };
00117 
00118 }  
00119 
00120 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines