Logo ROOT  
Reference Guide
TS3HTTPRequest.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fabio Hernandez 30/01/2013
3 // based on an initial version by Marcelo Sousa (class THTTPMessage)
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TS3HTTPRequest
14 #define ROOT_TS3HTTPRequest
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TS3HTTPRequest //
19 // //
20 // An object of this class represents an HTTP request extended to be //
21 // compatible with Amazon's S3 protocol. //
22 // Specifically, such a request contains an 'Authorization' header with //
23 // information used by the S3 server for authenticating this request. //
24 // The authentication information is computed based on a pair of access //
25 // key and secret key which are both provided to the user by the S3 //
26 // service provider (e.g. Amazon, Google, etc.). //
27 // The secret key is used to compute a signature of selected fields in //
28 // the request. The algorithm for computing the signature is documented //
29 // in: //
30 // //
31 // Google storage: //
32 // http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html#authentication
33 // //
34 // Amazon: //
35 // http://docs.aws.amazon.com/AmazonS3/latest/dev/S3_Authentication2.html
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #include "TObject.h"
40 
41 #include "TString.h"
42 
43 
44 
45 class TS3HTTPRequest : public TObject {
46 
47 public:
48 
49  enum EHTTPVerb { kGET, kPOST, kPUT, kDELETE, kHEAD, kCOPY };
50  enum EAuthType { kNoAuth, kAmazon, kGoogle };
51 
52 private:
53  EHTTPVerb fVerb; // HTTP Verb
54  EAuthType fAuthType; // Authentication type
55  TString fHost; // Host name
56  TString fBucket; // Bucket name
57  TString fObjectKey; // Object key
58  TString fTimeStamp; // Request time stamp
59  TString fAccessKey; // Access key (for authentication)
60  TString fSecretKey; // Secret key (for authentication)
61  TString fSessionToken; // Session token (for authentication)
62 
63 
64 protected:
69  TString MakeAuthPrefix() const;
70  TString MakeHostHeader() const;
71  TString MakeDateHeader() const;
72  TString MakeTokenHeader() const;
74 
75 public:
76 
78  TS3HTTPRequest(EHTTPVerb httpVerb, const TString& host,
79  const TString& bucket, const TString& objectKey,
80  EAuthType authType, const TString& accessKey,
81  const TString& secretKey);
83  virtual ~TS3HTTPRequest() { }
84 
85  EHTTPVerb GetHTTPVerb() const { return fVerb; }
86  const TString& GetHost() const { return fHost; }
87  const TString& GetBucket() const { return fBucket; }
88  const TString& GetObjectKey() const { return fObjectKey; }
89  const TString& GetTimeStamp() const { return fTimeStamp; }
90  const TString& GetAccessKey() const { return fAccessKey; }
91  const TString& GetSecretKey() const { return fSecretKey; }
92  TString GetAuthType() const { return fAuthType; }
94 
96  TS3HTTPRequest& SetBucket(const TString& bucket);
97  TS3HTTPRequest& SetObjectKey(const TString& objectKey);
98  TS3HTTPRequest& SetAccessKey(const TString& accessKey);
99  TS3HTTPRequest& SetSecretKey(const TString& secretKey);
100  TS3HTTPRequest& SetAuthKeys(const TString& accessKey, const TString& secretKey);
102  TS3HTTPRequest& SetSessionToken(const TString& token);
103 
104  ClassDef(TS3HTTPRequest, 0) // Create generic HTTP request for Amazon S3 and Google Storage services
105 };
106 
107 
108 //////////////////////////////////////////////////////////////////////////
109 // //
110 // Inlines //
111 // //
112 //////////////////////////////////////////////////////////////////////////
113 
115 {
116  fHost = host;
117  return *this;
118 }
119 
121 {
122  fBucket = bucket;
123  return *this;
124 }
125 
127 {
128  fObjectKey = objectKey;
129  return *this;
130 }
131 
132 inline TS3HTTPRequest& TS3HTTPRequest::SetAuthKeys(const TString& accessKey, const TString& secretKey)
133 {
134  fAccessKey = accessKey;
135  fSecretKey = secretKey;
136  return *this;
137 }
138 
140 {
141  fAuthType = authType;
142  return *this;
143 }
144 
146 {
147  fAccessKey = accessKey;
148  return *this;
149 }
150 
152 {
153  fSecretKey = secretKey;
154  return *this;
155 }
156 
158 {
159  fSessionToken = token;
160  return *this;
161 }
162 
163 #endif
m
auto * m
Definition: textangle.C:8
TS3HTTPRequest::MakeTokenHeader
TString MakeTokenHeader() const
Returns the session security token header for this HTTP request.
Definition: TS3HTTPRequest.cxx:210
TS3HTTPRequest
Definition: TS3HTTPRequest.h:45
TS3HTTPRequest::MakeRequestLine
TString MakeRequestLine(TS3HTTPRequest::EHTTPVerb httpVerb) const
Returns the first line of a HTTP request for this object.
Definition: TS3HTTPRequest.cxx:183
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TS3HTTPRequest::SetAuthKeys
TS3HTTPRequest & SetAuthKeys(const TString &accessKey, const TString &secretKey)
Definition: TS3HTTPRequest.h:132
TS3HTTPRequest::fVerb
EHTTPVerb fVerb
Definition: TS3HTTPRequest.h:59
TS3HTTPRequest::fObjectKey
TString fObjectKey
Definition: TS3HTTPRequest.h:63
TS3HTTPRequest::kGoogle
@ kGoogle
Definition: TS3HTTPRequest.h:56
TS3HTTPRequest::GetSecretKey
const TString & GetSecretKey() const
Definition: TS3HTTPRequest.h:97
TS3HTTPRequest::ComputeSignature
TString ComputeSignature(TS3HTTPRequest::EHTTPVerb httpVerb) const
Returns this request's signature.
Definition: TS3HTTPRequest.cxx:97
TS3HTTPRequest::kGET
@ kGET
Definition: TS3HTTPRequest.h:61
TS3HTTPRequest::SetObjectKey
TS3HTTPRequest & SetObjectKey(const TString &objectKey)
Definition: TS3HTTPRequest.h:126
TS3HTTPRequest::fAccessKey
TString fAccessKey
Definition: TS3HTTPRequest.h:65
TS3HTTPRequest::kHEAD
@ kHEAD
Definition: TS3HTTPRequest.h:61
TS3HTTPRequest::fSecretKey
TString fSecretKey
Definition: TS3HTTPRequest.h:66
TS3HTTPRequest::GetTimeStamp
const TString & GetTimeStamp() const
Definition: TS3HTTPRequest.h:95
TS3HTTPRequest::EAuthType
EAuthType
Definition: TS3HTTPRequest.h:56
TS3HTTPRequest::MakeAuthPrefix
TString MakeAuthPrefix() const
Returns the authentication prefix.
Definition: TS3HTTPRequest.cxx:225
TS3HTTPRequest::fTimeStamp
TString fTimeStamp
Definition: TS3HTTPRequest.h:64
TS3HTTPRequest::SetSessionToken
TS3HTTPRequest & SetSessionToken(const TString &token)
Definition: TS3HTTPRequest.h:157
TS3HTTPRequest::~TS3HTTPRequest
virtual ~TS3HTTPRequest()
Definition: TS3HTTPRequest.h:89
TS3HTTPRequest::GetHTTPVerb
EHTTPVerb GetHTTPVerb() const
Definition: TS3HTTPRequest.h:91
TS3HTTPRequest::GetObjectKey
const TString & GetObjectKey() const
Definition: TS3HTTPRequest.h:94
TS3HTTPRequest::fBucket
TString fBucket
Definition: TS3HTTPRequest.h:62
TS3HTTPRequest::SetTimeStamp
TS3HTTPRequest & SetTimeStamp()
Sets this request's time stamp according to: http://code.google.com/apis/storage/docs/reference-heade...
Definition: TS3HTTPRequest.cxx:158
TS3HTTPRequest::SetSecretKey
TS3HTTPRequest & SetSecretKey(const TString &secretKey)
Definition: TS3HTTPRequest.h:151
TString
Definition: TString.h:136
TString.h
bool
TS3HTTPRequest::fAuthType
EAuthType fAuthType
Definition: TS3HTTPRequest.h:60
TS3HTTPRequest::GetHost
const TString & GetHost() const
Definition: TS3HTTPRequest.h:92
TS3HTTPRequest::HTTPVerbToTString
TString HTTPVerbToTString(EHTTPVerb httpVerb) const
Definition: TS3HTTPRequest.cxx:141
TS3HTTPRequest::kPOST
@ kPOST
Definition: TS3HTTPRequest.h:61
TS3HTTPRequest::SetBucket
TS3HTTPRequest & SetBucket(const TString &bucket)
Definition: TS3HTTPRequest.h:120
TS3HTTPRequest::kNoAuth
@ kNoAuth
Definition: TS3HTTPRequest.h:56
TS3HTTPRequest::SetHost
TS3HTTPRequest & SetHost(const TString &host)
Definition: TS3HTTPRequest.h:114
TS3HTTPRequest::EHTTPVerb
EHTTPVerb
Definition: TS3HTTPRequest.h:55
TS3HTTPRequest::fSessionToken
TString fSessionToken
Definition: TS3HTTPRequest.h:67
TS3HTTPRequest::kAmazon
@ kAmazon
Definition: TS3HTTPRequest.h:56
TS3HTTPRequest::GetAccessKey
const TString & GetAccessKey() const
Definition: TS3HTTPRequest.h:96
TS3HTTPRequest::SetAccessKey
TS3HTTPRequest & SetAccessKey(const TString &accessKey)
Definition: TS3HTTPRequest.h:145
TS3HTTPRequest::SetAuthType
TS3HTTPRequest & SetAuthType(TS3HTTPRequest::EAuthType authType)
Definition: TS3HTTPRequest.h:139
TS3HTTPRequest::fHost
TString fHost
Definition: TS3HTTPRequest.h:61
TObject.h
TS3HTTPRequest::GetRequest
TString GetRequest(TS3HTTPRequest::EHTTPVerb httpVerb, Bool_t appendCRLF=kTRUE)
Returns the HTTP request ready to be sent to the server.
Definition: TS3HTTPRequest.cxx:253
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TS3HTTPRequest::kDELETE
@ kDELETE
Definition: TS3HTTPRequest.h:61
TS3HTTPRequest::kPUT
@ kPUT
Definition: TS3HTTPRequest.h:61
TS3HTTPRequest::GetAuthType
TString GetAuthType() const
Definition: TS3HTTPRequest.h:98
TS3HTTPRequest::kCOPY
@ kCOPY
Definition: TS3HTTPRequest.h:61
TS3HTTPRequest::MakeDateHeader
TString MakeDateHeader() const
Returns the date header for this HTTP request.
Definition: TS3HTTPRequest.cxx:202
TS3HTTPRequest::MakeHostHeader
TString MakeHostHeader() const
Returns the 'Host' header to include in the HTTP request.
Definition: TS3HTTPRequest.cxx:194
TS3HTTPRequest::GetBucket
const TString & GetBucket() const
Definition: TS3HTTPRequest.h:93
TS3HTTPRequest::TS3HTTPRequest
TS3HTTPRequest()
Definition: TS3HTTPRequest.cxx:57
TS3HTTPRequest::MakeAuthHeader
TString MakeAuthHeader(TS3HTTPRequest::EHTTPVerb httpVerb) const
Returns the authentication header for this HTTP request.
Definition: TS3HTTPRequest.cxx:238