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