| 1 | #include "s3url.h" |
| 2 | |
| 3 | S3Url::S3Url(const string &sourceUrl, bool useHttps, const string &version, const string ®ion) |
| 4 | : version(version), sourceUrl(sourceUrl), region(region) { |
| 5 | string schemaStr = useHttps ? "https" : "http"; |
| 6 | FindAndReplace(this->sourceUrl, "s3://", schemaStr + "://"); |
| 7 | |
| 8 | // else it was initialized with urlRegion |
| 9 | if (this->version == "1") { |
| 10 | extractRegionFromUrl(); |
| 11 | } else if (this->version.empty()) { |
| 12 | if (extractRegionFromUrl()) { |
| 13 | this->version = "1"; |
| 14 | } else { |
| 15 | this->version = "2"; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | http_parser_url urlParser; |
| 20 | int result = |
| 21 | http_parser_parse_url(this->sourceUrl.c_str(), this->sourceUrl.length(), false, &urlParser); |
| 22 | |
| 23 | S3_CHECK_OR_DIE(result == 0, S3RuntimeError, |
| 24 | "Failed to parse URL " + sourceUrl + " at field " + |
| 25 | std::to_string((unsigned long long)result)); |
| 26 | |
| 27 | this->schema = schemaStr; |
| 28 | this->host = extractField(&urlParser, UF_HOST); |
| 29 | this->port = extractField(&urlParser, UF_PORT); |
| 30 | |
| 31 | if (this->port != "443" && !this->port.empty() && useHttps) { |
| 32 | S3WARN("You are using https on port '%s'", this->port.c_str()); |
| 33 | } |
| 34 | |
| 35 | extractBucket(); |
| 36 | extractEncodedPrefix(); |
| 37 | } |
| 38 | |
| 39 | string S3Url::getFullUrlForCurl() const { |
| 40 | stringstream fullUrl; |
nothing calls this directly
no test coverage detected