13345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Use of this source code is governed by a BSD-style license that can be 3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// found in the LICENSE file. 4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef NET_HTTP_HTTP_TRANSACTION_H_ 6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define NET_HTTP_HTTP_TRANSACTION_H_ 73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 93345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "base/string16.h" 10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "net/base/completion_callback.h" 11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "net/base/load_states.h" 12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace net { 14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BoundNetLog; 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct HttpRequestInfo; 17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass HttpResponseInfo; 18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass IOBuffer; 19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass X509Certificate; 20731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickclass SSLHostInfo; 21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Represents a single HTTP transaction (i.e., a single request/response pair). 23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// HTTP redirects are not followed and authentication challenges are not 24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// answered. Cookies are assumed to be managed by the caller. 25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass HttpTransaction { 26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott public: 27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Stops any pending IO and destroys the transaction object. 28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual ~HttpTransaction() {} 29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Starts the HTTP transaction (i.e., sends the HTTP request). 31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns OK if the transaction could be started synchronously, which means 33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // that the request was served from the cache. ERR_IO_PENDING is returned to 34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // indicate that the CompletionCallback will be notified once response info 35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // is available or if an IO error occurs. Any other return value indicates 36c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // that the transaction could not be started. 37c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 38c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Regardless of the return value, the caller is expected to keep the 39c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // request_info object alive until Destroy is called on the transaction. 40c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // NOTE: The transaction is not responsible for deleting the callback object. 42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Profiling information for the request is saved to |net_log| if non-NULL. 44c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual int Start(const HttpRequestInfo* request_info, 45c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CompletionCallback* callback, 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const BoundNetLog& net_log) = 0; 47c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 48c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Restarts the HTTP transaction, ignoring the last error. This call can 49c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // only be made after a call to Start (or RestartIgnoringLastError) failed. 50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Once Read has been called, this method cannot be called. This method is 51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // used, for example, to continue past various SSL related errors. 52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Not all errors can be ignored using this method. See error code 54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // descriptions for details about errors that can be ignored. 55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // NOTE: The transaction is not responsible for deleting the callback object. 57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual int RestartIgnoringLastError(CompletionCallback* callback) = 0; 59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Restarts the HTTP transaction with a client certificate. 61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual int RestartWithCertificate(X509Certificate* client_cert, 62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CompletionCallback* callback) = 0; 63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Restarts the HTTP transaction with authentication credentials. 653345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick virtual int RestartWithAuth(const string16& username, 663345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick const string16& password, 67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CompletionCallback* callback) = 0; 68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns true if auth is ready to be continued. Callers should check 70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // this value anytime Start() completes: if it is true, the transaction 71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // can be resumed with RestartWithAuth(L"", L"", callback) to resume 72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // the automatic auth exchange. This notification gives the caller a 73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // chance to process the response headers from all of the intermediate 74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // restarts needed for authentication. 75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual bool IsReadyToRestartForAuth() = 0; 76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Once response info is available for the transaction, response data may be 78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // read by calling this method. 79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Response data is copied into the given buffer and the number of bytes 81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // copied is returned. ERR_IO_PENDING is returned if response data is not 82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // yet available. The CompletionCallback is notified when the data copy 83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // completes, and it is passed the number of bytes that were successfully 84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // copied. Or, if a read error occurs, the CompletionCallback is notified of 85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // the error. Any other negative return value indicates that the transaction 86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // could not be read. 87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // NOTE: The transaction is not responsible for deleting the callback object. 89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // If the operation is not completed immediately, the transaction must acquire 90c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // a reference to the provided buffer. 91c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // 92c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual int Read(IOBuffer* buf, int buf_len, 93c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CompletionCallback* callback) = 0; 94c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Stops further caching of this request by the HTTP cache, if there is any. 96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void StopCaching() = 0; 97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 98c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns the response info for this transaction or NULL if the response 99c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // info is not available. 100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual const HttpResponseInfo* GetResponseInfo() const = 0; 101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 102c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns the load state for this transaction. 103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual LoadState GetLoadState() const = 0; 104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 105c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns the upload progress in bytes. If there is no upload data, 106c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // zero will be returned. This does not include the request headers. 107c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual uint64 GetUploadProgress() const = 0; 108731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick 109731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // SetSSLHostInfo sets a object which reads and writes public information 110731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // about an SSL server. It's used to implement Snap Start. 111731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick // TODO(agl): remove this. 112731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick virtual void SetSSLHostInfo(SSLHostInfo*) { }; 113c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}; 114c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} // namespace net 116c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 117c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif // NET_HTTP_HTTP_TRANSACTION_H_ 118