Page Speed Optimization Libraries  1.5.27.2
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 
00055   void SetHeaders(ResponseHeaders* headers);
00056 
00061   virtual bool Write(const StringPiece& str, MessageHandler* handler);
00062   virtual bool Flush(MessageHandler* handler);
00063 
00065   bool ExtractHeaders(ResponseHeaders* headers, MessageHandler* handler) const;
00066 
00070   bool ExtractContents(StringPiece* str) const;
00071 
00073   bool unique() const { return storage_.unique(); }
00074 
00080   bool Link(SharedString* src, ResponseHeaders* headers,
00081             MessageHandler* handler);
00082 
00085   void Link(HTTPValue* src) {
00086     if (src != this) {
00087       storage_ = src->storage_; 
00088       contents_size_ = src->contents_size();
00089     }
00090   }
00091 
00093   SharedString* share() { return &storage_; }
00094 
00095   size_t size() const { return storage_.size(); }
00096   int64 contents_size() { return contents_size_; }
00097 
00098  private:
00099   friend class HTTPValueTest;
00100 
00102   char type_identifier() const { return *storage_.data(); }
00103 
00104   unsigned int SizeOfFirstChunk() const;
00105   void SetSizeOfFirstChunk(unsigned int size);
00106   int64 ComputeContentsSize() const;
00107 
00110   void CopyOnWrite();
00111 
00112   SharedString storage_;
00114   int64 contents_size_;
00115 
00116   DISALLOW_COPY_AND_ASSIGN(HTTPValue);
00117 };
00118 
00119 }  
00120 
00121 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines