@@ -9,21 +9,33 @@ public:
9
9
const std::string & s,
10
10
const std::string & akf,
11
11
const std::string & skf,
12
+ const std::string & b,
13
+ const std::string & o,
12
14
int sv = 4
13
15
) :
14
16
HTTPRequest ( s ),
15
17
accessKeyFile (akf),
16
18
secretKeyFile (skf),
17
- signatureVersion (sv)
19
+ signatureVersion (sv),
20
+ bucket (b),
21
+ object (o)
18
22
{
19
23
requiresSignature = true ;
20
- if (! parseURL (hostUrl, host, canonicalURI)) {
24
+ // Start off by parsing the hostUrl, which we use in conjunction with the bucket to fill in the host (for setting host header).
25
+ // For example, if the incoming hostUrl (which we get from config) is "https://my-url.com:443", the bucket is "my-bucket", and
26
+ // the object is "my-object", then the host will be "my-bucket.my-url.com:443" and the canonicalURI will be "/my-object".
27
+ if (! parseURL (hostUrl, b, o, host, canonicalURI)) {
21
28
errorCode = " E_INVALID_SERVICE_URL" ;
22
29
errorMessage = " Failed to parse host and canonicalURI from service URL." ;
23
30
}
24
31
25
32
if ( canonicalURI.empty () ) { canonicalURI = " /" ; }
26
33
34
+ // Now that we have the host and canonicalURI, we can build the actual url we perform the curl against.
35
+ // Using the previous example, we'd get a new hostUrl of "https://my-bucket.my-url.com:443/my-object".
36
+ hostUrl = protocol + " ://" +
37
+ host + canonicalURI;
38
+
27
39
// If we can, set the region based on the host.
28
40
size_t secondDot = host.find ( " ." , 2 + 1 );
29
41
if ( host.find ( " s3." ) == 0 ) {
@@ -38,6 +50,8 @@ public:
38
50
return &secretKeyFile; }
39
51
40
52
bool parseURL ( const std::string & url,
53
+ const std::string & bucket,
54
+ const std::string & object,
41
55
std::string & host,
42
56
std::string & path );
43
57
@@ -57,6 +71,9 @@ protected:
57
71
std::string host;
58
72
std::string canonicalURI;
59
73
74
+ std::string bucket;
75
+ std::string object;
76
+
60
77
std::string region;
61
78
std::string service;
62
79
@@ -76,21 +93,13 @@ public:
76
93
const std::string & b,
77
94
const std::string & o
78
95
) :
79
- AmazonRequest (s, akf, skf),
80
- bucket (b),
81
- object (o)
82
- {
83
- hostUrl = protocol + " ://" + bucket + " ." +
84
- host + canonicalURI + object;
85
- }
96
+ AmazonRequest (s, akf, skf, b, o){}
86
97
87
98
virtual ~AmazonS3Upload ();
88
99
89
100
virtual bool SendRequest ( const std::string & payload, off_t offset, size_t size );
90
101
91
102
protected:
92
- std::string bucket;
93
- std::string object;
94
103
std::string path;
95
104
};
96
105
@@ -104,21 +113,11 @@ public:
104
113
const std::string & b,
105
114
const std::string & o
106
115
) :
107
- AmazonRequest (s, akf, skf),
108
- bucket (b),
109
- object (o)
110
- {
111
- hostUrl = protocol + " ://" + bucket + " ." +
112
- host + canonicalURI + object;
113
- }
116
+ AmazonRequest (s, akf, skf, b, o){}
114
117
115
118
virtual ~AmazonS3Download ();
116
119
117
120
virtual bool SendRequest ( off_t offset, size_t size );
118
-
119
- protected:
120
- std::string bucket;
121
- std::string object;
122
121
};
123
122
124
123
class AmazonS3Head : public AmazonRequest {
@@ -131,21 +130,11 @@ public:
131
130
const std::string & b,
132
131
const std::string & o
133
132
) :
134
- AmazonRequest (s, akf, skf),
135
- bucket (b),
136
- object (o)
137
- {
138
- hostUrl = protocol + " ://" + bucket + " ." +
139
- host + canonicalURI + object;
140
- }
133
+ AmazonRequest (s, akf, skf, b, o){}
141
134
142
135
virtual ~AmazonS3Head ();
143
136
144
137
virtual bool SendRequest ();
145
-
146
- protected:
147
- std::string bucket;
148
- std::string object;
149
138
};
150
139
151
140
#endif /* S3_COMMANDS_H */
0 commit comments