Google APIs Client Library for C++
http_transport.h
Go to the documentation of this file.
00001 /*
00002  * \copyright Copyright 2013 Google Inc. All Rights Reserved.
00003  * \license @{
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  *
00017  * @}
00018  */
00019 
00020 
00021 /*
00022  * @defgroup TransportLayerCore Transport Layer - Core Components
00023  *
00024  * The HTTP transport layer provides lower-level support for interacting
00025  * with standard HTTP/1.1 web servers. In particular those that are used
00026  * to host cloud-based services such as the Google Cloud Platform. Much if
00027  * not all of it can be used for other HTTP servers and uses. In fact, the
00028  * Google APIs Client Library for C++ uses it in the OAuth 2.0 module for
00029  * messaging with OAuth 2.0 servers.
00030  *
00031  * The HTTP transport layer is designed as a keystone building block to
00032  * implement the Google APIs Client Library for C++. One aspect of this is
00033  * that it does not explicitly dictate a particular implementation for the
00034  * physical HTTP messaging. Instead it chiefly provides an abstraction for
00035  * messaging and a means for "plugging in" implementation details for the
00036  * physical messaging. To be useful, it provides a reasonable implementation
00037  * suitable for most purposes. However some clients or situations may wish
00038  * to use some other mechanism, especially pre-existing ones in their
00039  * runtime environments. This is accomodated by the HttpTransport class.
00040  *
00041  * In addiition to the HttpTransport class, the core HTTP transport layer
00042  * also includes the HttpRequest, HttpRequestState and HttpResponse and
00043  * httpTransportErrorHandler classes. It also includes an abstract
00044  * AuthorizationCredential class for making authorized requests.
00045  * The Google APIs Client Library for C++ builds on this abstract class
00046  * to provide OAuth 2.0 support in the OAuth2 2.0 module. Together
00047  * this allows the transport layer to be used to comply with OAuth 2.0
00048  * protected resources without actually depending on a specific client-side
00049  * implementation of OAuth 2.0.
00050  */
00051 
00052 #ifndef APISERVING_CLIENTS_CPP_TRANSPORT_HTTP_TRANSPORT_H_
00053 #define APISERVING_CLIENTS_CPP_TRANSPORT_HTTP_TRANSPORT_H_
00054 
00055 #include <string>
00056 using std::string;
00057 #include <map>
00058 using std::map;
00059 #include "googleapis/base/callback.h"
00060 #include "googleapis/base/macros.h"
00061 #include "googleapis/base/scoped_ptr.h"
00062 #include "googleapis/client/transport/http_request.h"
00063 namespace googleapis {
00064 
00065 namespace thread {
00066 class Executor;
00067 }  // namespace thread
00068 
00069 namespace client {
00070 
00071 class HttpScribe;
00072 class HttpTransportFactory;  // forward declaration
00073 class HttpTransportLayerConf;  // forward declaration
00074 
00075 /*
00076  * Specifies the error handling policy for HTTP messaging.
00077  * @ingroup TransportLayerCore
00078  *
00079  * This class specifies the policy for different types of errors including:
00080  * <ul>
00081  *   <li>Transport erors
00082  *   <li>HTTP redirect responses
00083  *   <li>HTTP error response codes
00084  * </ul>
00085  *
00086  * Instances can further refine specific error handling for individual HTTP
00087  * status codes.
00088  *
00089  * @see HttpRequest
00090  */
00091 class HttpTransportErrorHandler {
00092  public:
00093   /*
00094    * Callback for handling a specific HTTP status code.
00095    *
00096    * @param[in] int The HTTP status code.
00097    * @param[in] HttpRequest The request that had the error.
00098    * @return true if the callback requests a retry, false if not.
00099    *
00100    * The callback and make changes to the request to indicate how to
00101    * perform a retry.
00102    */
00103   typedef ResultCallback2<bool, int, HttpRequest*> HttpCodeHandler;
00104 
00105   /*
00106    * Replaces the existing handler for a given HTTP status code.
00107    *
00108    * @param[in] code The HTTP status code to handle.
00109    * @param[in] handler The handler to use can be NULL to remove it.
00110    *                    Ownership is passed.
00111    * non-NULL handlers must be a repeatable callback since it can be
00112    * alled multiple times.
00113    *
00114    * @see NewPermanentCallback()
00115    */
00116   void ResetHttpCodeHandler(int code, HttpCodeHandler* handler);
00117 
00118   /*
00119    * Standard constructor.
00120    */
00121   HttpTransportErrorHandler();
00122 
00123   /*
00124    * Standard destructor.
00125    */
00126   virtual ~HttpTransportErrorHandler();
00127 
00128   /*
00129    * Handles transport errors.
00130    *
00131    * @param[in] num_retries_so_far Number of retries performed already.
00132    * @param[in] request The request that caused the error.
00133    *
00134    * @return true if we should consider trying again, policy permitting.
00135    */
00136   virtual bool HandleTransportError(
00137       int num_retries_so_far, HttpRequest* request) const;
00138 
00139   /*
00140    * Handles HTTP redirects (HTTP 3xx series results).
00141    *
00142    * @param[in] num_redirects_so_far Number of redirects already followed.
00143    * @param[in] request The request that caused the error.
00144    *
00145    * @return true if we should consider trying again, policy permitting.
00146    */
00147   virtual bool HandleRedirect(
00148       int num_redirects_so_far, HttpRequest* request) const;
00149 
00150   /*
00151    * Handles erorrs from requests with HTTP status code errors.
00152    *
00153    * This includes 401 (Authorization) and 503 (Unavailable)
00154    *
00155    * @param[in] num_retries_so_far Number of retries performed already.
00156    * @param[in] request The request that returned the error.
00157    *
00158    * @return true if we should consider trying again, policy permitting.
00159    *
00160    * @see ResetHttpCodeHandler for overriding this behavior before subclassing.
00161    */
00162   virtual bool HandleHttpError(
00163       int num_retries_so_far, HttpRequest* request) const;
00164 
00165  private:
00166   /*
00167    * Maps HTTP status code to specific handler for it.
00168    */
00169   map<int, HttpCodeHandler*>  specialized_http_code_handlers_;
00170 
00171   DISALLOW_COPY_AND_ASSIGN(HttpTransportErrorHandler);
00172 };
00173 
00174 /*
00175  * Configures options on an HttpTransport instance
00176  * @ingroup TransportLayerCore
00177  *
00178  * Each HttpTransport instance maintains its own options however typically
00179  * the default options are set on the HttpTransportFactory so that the
00180  * options will apply to all transport instances. Sometimes you may in fact
00181  * want to configure an an individual instance in some special way.
00182  *
00183  * Options are simple data objects so support assignment and the copy
00184  * constructor.
00185  *
00186  * @see HttpTransport
00187  * @see HttpTransportFactory::mutable_default_transport_options()
00188  */
00189 class HttpTransportOptions {
00190  public:
00191   /*
00192    * Standard constructor.
00193    *
00194    * The options will be constructed without an error handler or executor.
00195    * It will use the default cacerts_path for SSL verification the default
00196    * application name in the user agent.
00197    *
00198    * @see DetermineDefaultApplicationName
00199    * @see DetermineDefaultCaCertsPath
00200    */
00201   HttpTransportOptions();
00202 
00203   /*
00204    * Standard destructor.
00205    */
00206   virtual ~HttpTransportOptions();
00207 
00208   /*
00209    * Set the executor to use for asynchronous requests.
00210    *
00211    * Setting the executor to NULL will use the global default executor.
00212    *
00213    * @param[in] executor The executor this transport will use. The caller
00214    * retains ownership so should guarantee that the executor will remain
00215    * valid over the lifetime of these options and any options assigned from it.
00216    */
00217   void set_executor(thread::Executor* executor)  { executor_ = executor; }
00218 
00219   /*
00220    * Returns the executor that should be used with this transport.
00221    *
00222    * @return  If the transport is using the global default hten the global
00223    *          default will be returned. This might still be NULL if no global
00224    *          default was set.
00225    */
00226   thread::Executor* executor() const;
00227 
00228   /*
00229    * Returns the error handler for this transport.
00230    *
00231    * The default options have the standard built-in error handler pre-assigned.
00232    *
00233    * @return NULL if no error handler has been set.
00234    */
00235   const HttpTransportErrorHandler* error_handler() const {
00236     return error_handler_;
00237   }
00238 
00239   /*
00240    * Replaces the error handler to use on this transport.
00241    *
00242    * @param[in] error_handler/ NULL indicates do not perform any error
00243    *            handling. Caller retains ownership.
00244    */
00245   void set_error_handler(const HttpTransportErrorHandler* error_handler) {
00246     error_handler_ = error_handler;
00247   }
00248 
00249   /*
00250    * Returns the value used for the HTTP User-Agent header.
00251    *
00252    * We recommend using SetApplicationName to change the application name
00253    * if the default is not appropriate. Use set_nonstandard_user_agent to
00254    * change the default to an arbitrary literal value if you must.
00255    */
00256   const string& user_agent() const { return user_agent_; }
00257 
00258   /*
00259    * Refines the user agent to use the given application name.
00260    *
00261    * @param[in] name The application name to use within the User-Agent header.
00262    *
00263    * @see DetermineDefaultApplicationName
00264    */
00265   void SetApplicationName(const StringPiece& name);
00266 
00267   /*
00268    * Sets an exact literal value to use for the HTTP User-Agent header.
00269    *
00270    * You may use this, but we would prefer you use SetApplicationName instead,
00271    * especially if talking to servers hosted on the Google Cloud Platform.
00272    *
00273    * @see SetApplicationName
00274    */
00275   void set_nonstandard_user_agent(const string& agent);
00276 
00277   /*
00278    * Returns true if SSL verification has been disabled.
00279    *
00280    * To disable SSL verification you must explicitly set the cacerts_path
00281    * to kDisableSslVerification.
00282    */
00283   bool ssl_verification_disabled() const { return ssl_verification_disabled_; }
00284 
00285   /*
00286    * Returns the path to the SSL certificate authority validation data.
00287    */
00288   const string& cacerts_path() const     { return cacerts_path_; }
00289 
00290   /*
00291    * Sets the path to the SSL certificate authority validation data.
00292    *
00293    * @see DetermineDefaultCaCertsPath
00294    */
00295   void set_cacerts_path(const StringPiece& path);
00296 
00297   /*
00298    * An identifier used to declare this client library within the User-Agent.
00299    */
00300   static const StringPiece kGoogleApisUserAgent;
00301 
00302   /*
00303    * A magical cacerts_path value indicating we intend on disabling
00304    * the ca certificate validation.
00305    */
00306   static const StringPiece kDisableSslVerification;
00307 
00308   /*
00309    * Returns the default application name assumed for this process.
00310    *
00311    * The default name will be the filename of the program that is
00312    * curently running (without other path elements).
00313    */
00314   static string DetermineDefaultApplicationName();
00315 
00316   /*
00317    * Returns the default location of the SSL certificate validation data.
00318    *
00319    * The default location is assumed to be the same directory as the
00320    * executable for the running process in a file called 'roots.pem'.
00321    */
00322   static string DetermineDefaultCaCertsPath();
00323 
00324  private:
00325   /*
00326    * The value for the User-Agent header identifying this client.
00327    */
00328   string user_agent_;
00329 
00330   /*
00331    * The path to the SSL certificate validation file.
00332    */
00333   string cacerts_path_;
00334 
00335   /*
00336    * True if SSL validation is disabled.
00337    */
00338   bool ssl_verification_disabled_;
00339 
00340 
00341   /*
00342    * Specifies the executor to use for asynchronous requests.
00343    *
00344    * Not owned. NULL means use global default.
00345    */
00346   thread::Executor* executor_;
00347 
00348   /*
00349    * Specifies the error handler to use.
00350    *
00351    * Not owned. NULL means no error handling.
00352    */
00353   const HttpTransportErrorHandler* error_handler_;
00354 };
00355 
00356 
00357 /*
00358  * Specifies the implementation components for the TransportLayer.
00359  * @ingroup TransportLayerCore
00360  */
00361 class HttpTransportLayerConfig {
00362  public:
00363   /*
00364    * Standard constructor does not bind a default HttpTransportFactory.
00365    *
00366    * The default configuration does not bind a specific transport factory
00367    * so you must add one yourself. For the application name and SSL certificate
00368    * validation see the static methods that determine the default values for
00369    * more details.
00370    *
00371    * @see DetermineDefaultCaCertsPath();
00372    * @see DetermineDefaultApplicationName();
00373    */
00374   HttpTransportLayerConfig();
00375 
00376   /*
00377    * Standard destructor.
00378    */
00379   virtual ~HttpTransportLayerConfig();
00380 
00381   /*
00382    * Sets the default transport factory.
00383    *
00384    * @param[in] factory Ownership is passed to the configuration.
00385    *            NULL will unset the default factory.
00386    */
00387   void ResetDefaultTransportFactory(HttpTransportFactory* factory);
00388 
00389   /*
00390    * Returns the default transport factory, if one was set.
00391    *
00392    * @warning
00393    * There is no default transport factory. You must explicitly set it.
00394    *
00395    * @return The configuration maintains ownership. NULL is returned if there
00396    *         is no factory set.
00397    */
00398   HttpTransportFactory* default_transport_factory() const {
00399     return default_transport_factory_.get();
00400   }
00401 
00402   /*
00403    * Returns the default HttpTransport options for this configuration.
00404    *
00405    * The returned options can be copied and modified for each transport
00406    * independently.
00407    */
00408   const HttpTransportOptions& default_transport_options() const {
00409     return default_options_;
00410   }
00411 
00412   /*
00413    * Returns a modifiable instance for changing the default HttpTransport
00414    * options.
00415    */
00416   HttpTransportOptions* mutable_default_transport_options() {
00417     return &default_options_;
00418   }
00419 
00420   /*
00421    * Returns a new transport using the default transport factory with the
00422    * default user agent set.
00423    *
00424    * @param[out] status Reason for failure if NULL is returned
00425    * @return New transport instance created by the default transport factory.
00426    *
00427    * This method requires that ResetDefaultTransportFactory was
00428    * called or it will return NULL and set an error status.
00429    *
00430    * @see ResetDefaultTransportFactory
00431    */
00432   HttpTransport* NewDefaultTransport(util::Status* status) const;
00433 
00434   /*
00435    * Create a new transport or terminate the program on failure.
00436    *
00437    * Similar to NewDefaultTransport but will CHECK-fail rather than returning
00438    * NULL if there is not default transport factory to use.
00439    *
00440    * @see ResetDefaultTransportFactory
00441    */
00442   HttpTransport* NewDefaultTransportOrDie() const;
00443 
00444   /*
00445    * Resets the error handler used by the default options, passing ownership.
00446    *
00447    * The HttpTransportOptions does not own its error handler. This method
00448    * changes the error handler in the default transport options but passes
00449    * ownership of that handler to this configuration. Otherwise the caller
00450    * would need to take responsibility for it if it set the handler directly
00451    * in the mutable_default_transport_options.
00452    *
00453    * This method will destroy any previous default error handler that was
00454    * owned by this configuration. If there were other HttpTransportOptions
00455    * previously using it then they will become corrupted with an invalid
00456    * pointer to the old (deleted) handler.
00457    *
00458    * @param[in] error_handler Ownership is passed to the configuration.
00459    *            NULL will unset the default error handler in the options
00460    *            as well.
00461    */
00462   void ResetDefaultErrorHandler(HttpTransportErrorHandler* error_handler);
00463 
00464   /*
00465    * Resets the executor used by the default options, passing ownership.
00466    *
00467    * The HttpTransportOptions does not own its executor. This method
00468    * changes the executor in the default transport options but passes
00469    * ownership of that handler to this configuration. Otherwise the caller
00470    * would need to take responsibility for it if it set the handler directly
00471    * in the mutable_default_transport_options.
00472    *
00473    * This method will destroy any previous default executor that was
00474    * owned by this configuration. If there were other HttpTransportOptions
00475    * previously using it then they will become corrupted with an invalid
00476    * pointer to the old (deleted) handler.
00477    *
00478    * @param[in] executor Ownership is passed to the configuration.
00479    *            NULL will unset the default executor in the options as well.
00480    */
00481   void ResetDefaultExecutor(thread::Executor* executor);
00482 
00483  private:
00484   HttpTransportOptions default_options_;
00485   scoped_ptr<HttpTransportFactory> default_transport_factory_;
00486   scoped_ptr<HttpTransportErrorHandler> default_error_handler_;
00487   scoped_ptr<thread::Executor> default_executor_;
00488 
00489   DISALLOW_COPY_AND_ASSIGN(HttpTransportLayerConfig);
00490 };
00491 
00492 
00493 /*
00494  * Abstract interface defining an HTTP transport will be specialized
00495  * for different concrete mechanisms for interacting with HTTP servers.
00496  * @ingroup TransportLayerCore
00497  *
00498  * This is an abstract interface that acts as the base class for all
00499  * Http Transports used by the Google APIs for C++ runtime library.
00500  *
00501  * It is recommended that you always use this class when defining classes and
00502  * interfaces rather than the concrete subclasses. It is recommended that you
00503  * create instances using factory -- either HttpTransportFactory or
00504  * <code>HttpTransportLayerConfig::NewDefaultTransport()</code> on an
00505  * <code>HttpTransportLayerConfig</code> instance.
00506  *
00507  * An HttpTransport instance is stateless. It can accomodate multiple
00508  * outstanding requests to different servers at the same time. There is no
00509  * technical reason to have multiple instances other than wanting different
00510  * configurations, such as standard request options.
00511  *
00512  * You must set the HttpTransportOptions::set_cacerts_path() with the path to
00513  * a file to validate SSL certificates. The SDK provides a "roots.pem"
00514  * which can validate all the certificates used by Google Cloud Platform
00515  * servers and other commonly used certificates. To disable SSL verification
00516  * you can set it to HttpTransportOptions::kDisableSslValidation,
00517  * though doing so will lose security against some forms of SSL attacks.
00518  *
00519  * @see HttpRequest
00520  * @see HttpTransportFactory
00521  * @see HttpTransportLayerConfig
00522  * @see HttpTransportOptions
00523  */
00524 class HttpTransport {
00525  public:
00526   /*
00527    * Construct the transport using the provided options.
00528    *
00529    * @param[in] options The options to configure the transport with.
00530    *
00531    * The options will be copied into a local attribute managed by this
00532    * instance. To make changes once this instance has been constructed
00533    * use mutable_transport_options().
00534    */
00535   explicit HttpTransport(const HttpTransportOptions& options);
00536 
00537   /*
00538    * Starndard destructor
00539    */
00540   virtual ~HttpTransport();
00541 
00542   /*
00543    * Returns the value of the User-Agent header for this transport instance.
00544    *
00545    * To change the value, modify the options.
00546    */
00547   const string& user_agent() const { return options().user_agent(); }
00548 
00549   /*
00550    * Retrieve the transport options for this instance
00551    */
00552   const HttpTransportOptions& options() const  { return options_; }
00553 
00554   /*
00555    * Get the options to modify this instance.
00556    *
00557    * Changing the result options will affect the configuration of this
00558    * instance but might not have effect on existing requests.
00559    */
00560   HttpTransportOptions* mutable_options()     { return &options_; }
00561 
00562   /*
00563    * Returns the default options used to initialize new HttpRequest instances.
00564    */
00565   const HttpRequestOptions& default_request_options() const {
00566     return default_request_options_;
00567   }
00568 
00569   /*
00570    * Returns modifiable options used to initialize new HttpRequest instances.
00571    *
00572    * Changing the options will affect new requests created but will not
00573    * affect any existing requests.
00574    */
00575   HttpRequestOptions* mutable_default_request_options() {
00576     return &default_request_options_;
00577   }
00578 
00579   /*
00580    * The transport id is used to tag instances for debug/tracing purposes.
00581    *
00582    * The default convention is to use simply the type of transport (ie 'curl').
00583    */
00584   void set_id(const StringPiece& id)  { id_ = id.as_string(); }
00585 
00586   /*
00587    * Returns the instance id for debug/tracing purposes.
00588    */
00589   const string& id() const  { return id_; }
00590 
00591   /*
00592    * Sets (or clears) the request scribe.
00593    *
00594    * Scribes incur significant overhead so are not indended for production
00595    * use. They are for debugging, testing, and diagnostics.
00596    *
00597    * @param[in] scribe The caller maintains ownership. NULL clears the scribe.
00598    */
00599   void set_scribe(HttpScribe* scribe) { scribe_ = scribe; }
00600 
00601   /*
00602    * Returns the bound scribe, if any.
00603    *
00604    * @return NULL if no scribe is bound.
00605    */
00606   HttpScribe* scribe() const { return scribe_; }
00607 
00608   /*
00609    * Create a new HttpRequest instance that will use this transport.
00610    *
00611    * This method is the HttpRequest factory. It is the preferred (and often
00612    * only) way to instantiate a request.
00613    *
00614    * @return a new HttpRequest
00615    */
00616   virtual HttpRequest* NewHttpRequest(
00617       const HttpRequest::HttpMethod& method) = 0;
00618 
00619  private:
00620   string id_;
00621   HttpTransportOptions options_;
00622   HttpRequestOptions default_request_options_;
00623   HttpScribe* scribe_;  // Reference is not owned
00624 
00625   DISALLOW_COPY_AND_ASSIGN(HttpTransport);
00626 };
00627 
00628 
00629 /*
00630  * Abstract interface for creating concrete HttpTransport instances.
00631  * @ingroup TransportLayerCore
00632  *
00633  * This class implements a Factory pattern for instantiating new HttpTransport
00634  * instances. It acts as the base class for all HttpTransport factories used
00635  * by the Google APIs Client Library for C++ runtime library.
00636  *
00637  * It is recommended that you always use this class when defining classes and
00638  * interfaces rather than the concrete subclasses. If you need a factory but
00639  * do not care about the implementation, consider
00640  * HttpTransport::default_transport_factory().
00641  *
00642  * Current HttpTransport::default_transport_factory must be explicit set at
00643  * some point during execution (such as application startup).
00644  *
00645  * @see New
00646  */
00647 class HttpTransportFactory {
00648  public:
00649   /*
00650    * Default constructor creates instances with the default configuration
00651    * default <code>HttpTransportOptions</code>.
00652    *
00653    * This method still calls DoAlloc with the default options.
00654    */
00655   HttpTransportFactory();
00656 
00657   /*
00658    * Standard constructor.
00659    *
00660    * Caller maintains ownership of the configuration, which can be shared
00661    * across mutliple factory instances.
00662    *
00663    * @param[in] config If NULL then this behaves similar to the
00664    *            default constructor. If non-null the caller retains ownership.
00665    *
00666    * @note
00667    * This factory instance is independent of the default_transport_factory
00668    * in the config. If you want to use this instance as the default in the
00669    * config then call config->ResetDefaultTransportFactory with this instance
00670    * after the constructor returns.
00671    */
00672   explicit HttpTransportFactory(const HttpTransportLayerConfig* config);
00673 
00674   /*
00675    * Standard destructor.
00676    */
00677   virtual ~HttpTransportFactory();
00678 
00679   /*
00680    * Construct a new transport instance with the provided options.
00681    */
00682   HttpTransport* NewWithOptions(const HttpTransportOptions& options);
00683 
00684   /*
00685    * Construct a new instance using the default transport options given
00686    * to this factory instance.
00687    */
00688   HttpTransport* New() {
00689     return NewWithOptions(config_
00690                           ? config_->default_transport_options()
00691                           : HttpTransportOptions());
00692   }
00693 
00694   /*
00695    * Get the modifiable default request options given the transport instances
00696    * created by this factory.
00697    *
00698    * Changing these options will affect future transport instances created
00699    * but will not affect exsting transport or request instances.
00700    */
00701   HttpRequestOptions* mutable_request_options()  {
00702     return &default_request_options_;
00703   }
00704 
00705   /*
00706    * Returns the default request options assigned by this factory instance.
00707    */
00708   const HttpRequestOptions& default_request_options() const {
00709     return default_request_options_;
00710   }
00711 
00712   /*
00713    * Returns the default id to assign new transport instances created.
00714    */
00715   const string& default_id() const      { return default_id_; }
00716 
00717   /*
00718    * Change the default transport identifier for new instances.
00719    *
00720    * @param[in] id The initial identifier to use for new instances is typically
00721    *               the name of the transport implementation.
00722    *
00723    * @see HttpTransport::id()
00724    */
00725   void set_default_id(const StringPiece& id) { default_id_ = id.as_string(); }
00726 
00727   /*
00728    * Sets the scribe to bind to instances.
00729    *
00730    * If this is non-NULL then it must remain valid until any transports
00731    * created with this factory are finished. Since the factory will own the
00732    * scribe, that means the factory cannot be destroyed either until all
00733    * transports created from this are no longer in used.
00734    *
00735    * @param[in] scribe Ownership is passed. NULL will clear.
00736    */
00737   void reset_scribe(HttpScribe* scribe);
00738 
00739   /*
00740    * Returns the scribe, if any.
00741    */
00742   HttpScribe* scribe() { return scribe_.get(); }
00743 
00744   /*
00745    * Returns the configuration that this factory was constructed with.
00746    *
00747    * @return NULL if it just uses the defaults.
00748    */
00749   const HttpTransportLayerConfig* config() { return config_; }
00750 
00751  protected:
00752   /*
00753    * Specialized factories override this method to create new instances.
00754    *
00755    * The base class will add the scribe and other factory configurations.
00756    */
00757   virtual HttpTransport* DoAlloc(const HttpTransportOptions& options) = 0;
00758 
00759  private:
00760   const HttpTransportLayerConfig* config_;
00761   HttpRequestOptions default_request_options_;
00762   scoped_ptr<HttpScribe> scribe_;
00763   string default_id_;
00764 
00765   DISALLOW_COPY_AND_ASSIGN(HttpTransportFactory);
00766 };
00767 
00768 }  // namespace client
00769 
00770 } // namespace googleapis
00771 #endif  // APISERVING_CLIENTS_CPP_TRANSPORT_HTTP_TRANSPORT_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines