11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// A class that stores the common state between HttpBasicStream and 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// WebSocketBasicHandshakeStream. 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef NET_HTTP_HTTP_BASIC_STATE_H_ 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define NET_HTTP_HTTP_BASIC_STATE_H_ 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <string> 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/basictypes.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/memory/ref_counted.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "net/base/completion_callback.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "net/base/net_export.h" 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "net/base/request_priority.h" 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace net { 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class BoundNetLog; 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class ClientSocketHandle; 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class GrowableIOBuffer; 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class HttpStreamParser; 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)struct HttpRequestInfo; 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class NET_EXPORT_PRIVATE HttpBasicState { 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) HttpBasicState(ClientSocketHandle* connection, bool using_proxy); 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ~HttpBasicState(); 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Initialize() must be called before using any of the other methods. 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int Initialize(const HttpRequestInfo* request_info, 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RequestPriority priority, 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const BoundNetLog& net_log, 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const CompletionCallback& callback); 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) HttpStreamParser* parser() const { return parser_.get(); } 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool using_proxy() const { return using_proxy_; } 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Deletes |parser_| and sets it to NULL. 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void DeleteParser(); 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ClientSocketHandle* connection() const { return connection_.get(); } 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<ClientSocketHandle> ReleaseConnection(); 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_refptr<GrowableIOBuffer> read_buf() const; 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Generates a string of the form "METHOD PATH HTTP/1.1\r\n", based on the 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // values of request_info_ and using_proxy_. 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string GenerateRequestLine() const; 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_refptr<GrowableIOBuffer> read_buf_; 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<HttpStreamParser> parser_; 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<ClientSocketHandle> connection_; 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const bool using_proxy_; 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const HttpRequestInfo* request_info_; 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(HttpBasicState); 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace net 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // NET_HTTP_HTTP_BASIC_STATE_H_ 73