Google APIs Client Library for C++
curl_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  * @defgroup TransportLayerTransport Transport Layer - Concrete Transports
00022  *
00023  * The HTTP transport layer does not include any specific HTTP implementations.
00024  * This module contains concrete transport implementations that can be used
00025  * in practice. These transports use specialized classes and the injection
00026  * mechanisms provided by the core transport layer in order to seamlessly
00027  * integrate concrete implementations.
00028  *
00029  * Additional transports can be found in among the Transport Layer Testing
00030  * components.
00031  */
00032 #ifndef APISERVING_CLIENTS_CPP_TRANSPORT_CURL_HTTP_TRANSPORT_H_
00033 #define APISERVING_CLIENTS_CPP_TRANSPORT_CURL_HTTP_TRANSPORT_H_
00034 
00035 #include <string>
00036 using std::string;
00037 #include "googleapis/client/transport/http_request.h"
00038 #include "googleapis/client/transport/http_transport.h"
00039 #include "googleapis/base/macros.h"
00040 namespace googleapis {
00041 
00042 namespace client {
00043 /*
00044  * A concrete HttpTransport that is implemented using the open source CURL
00045  * library.
00046  * @ingroup TransportLayerTransport
00047  *
00048  * A curl transport is capable of having multiple requests running and talking
00049  * to multiple servers. For future optimization purposes, it is suggested that
00050  * you use a single CurlHttpTransport instances for all requests sent to the
00051  * same service, but use different instances to talk to different services.
00052  * This is not required but might have better performance as the implementation
00053  * is tuned and optimized.
00054  *
00055  * It is recommended to not use this class directly, especially
00056  * in library code. Use the generic HttpTransport and HttpTransportFactory
00057  * unless you specifically want to use curl for some reason.
00058  *
00059  * The Google APIs for C++ Client Library is designed to accomodate
00060  * external transport implementations and eliminating a dependency on
00061  * curl entirely. If you use this class directly then you will be interfering
00062  * with that property.
00063  *
00064  * @see HttpTransport::set_default_transport_factory
00065  */
00066 class CurlHttpTransport : public HttpTransport {
00067  public:
00068   /*
00069    * Overrides default options while constructing.
00070    *
00071    * @param[in] options The options to use when configuring the transport are
00072    *            copied into the instance.
00073    */
00074   explicit CurlHttpTransport(const HttpTransportOptions& options);
00075 
00076   /*
00077    * Standard destructor.
00078    */
00079   virtual ~CurlHttpTransport();
00080 
00081   /*
00082    * Creates new HttpRequest that will be executed using the transport.
00083    *
00084    * @param[in] method The HTTP request method to use when constructing
00085    *            the request.
00086    *
00087    * @return Passes ownerhip of the request back to the caller. The request
00088    *         needs this transport instance so the caller must guarantee that
00089    *         this transport is not destroyed before it finishes using the
00090    *         request.
00091    */
00092   virtual HttpRequest* NewHttpRequest(const HttpRequest::HttpMethod& method);
00093 
00094   /*
00095    * The default id() attribute value identifying curl transport instances.
00096    */
00097   static const StringPiece kTransportIdentifier;
00098 
00099  private:
00100   DISALLOW_COPY_AND_ASSIGN(CurlHttpTransport);
00101 };
00102 
00103 /*
00104  * Factory for creating CurlHttpTransport instances.
00105  * @ingroup TransportLayerTransport
00106  *
00107  * It is recommended not to use this class directly except at the
00108  * point you are injecting curl as the Http Transport implementation.
00109  * This should be at application-level configuration.
00110  * <pre>
00111  *   HttpTransport::set_default_transport_factory(new CurlHttpTransportFactory)
00112  * </pre>
00113  */
00114 class CurlHttpTransportFactory : public HttpTransportFactory {
00115  public:
00116   /*
00117    * Default constructor.
00118    */
00119   CurlHttpTransportFactory();
00120 
00121   /*
00122    * Standard constructor.
00123    */
00124   explicit CurlHttpTransportFactory(const HttpTransportLayerConfig* config);
00125 
00126   /*
00127    * Standard destructor.
00128    */
00129   virtual ~CurlHttpTransportFactory();
00130 
00131   /*
00132    * Creates a new instance of a CurlHttpTransport with overriden options.
00133    *
00134    * @param[in] options The options to use when configuring the transport are
00135    *            copied into the instance.
00136    *
00137    * @return ownership of the new transport is passed back to the caller.
00138    */
00139   static HttpTransport* NewCurlHttpTransport(
00140       const HttpTransportOptions& options);
00141 
00142  protected:
00143   /*
00144    * Creates a new transport with overrided options.
00145    *
00146    * @param[in] options The options will override the options in the factory
00147    *            that are used to configure new transports created.
00148    *            The options are copied into the new instance.
00149    * @return ownership of the new transport is passed back to the caller.
00150    */
00151   virtual HttpTransport* DoAlloc(const HttpTransportOptions& options);
00152 
00153  private:
00154   DISALLOW_COPY_AND_ASSIGN(CurlHttpTransportFactory);
00155 };
00156 
00157 }  // namespace client
00158 
00159 } // namespace googleapis
00160 #endif  // APISERVING_CLIENTS_CPP_TRANSPORT_CURL_HTTP_TRANSPORT_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines