MCPcopy Create free account
hub / github.com/apache/trafficserver / uriEncode

Function uriEncode

plugins/origin_server_auth/aws_auth_v4.cc:81–108  ·  view source on GitHub ↗

* @brief URI-encode a character string (AWS specific version, see spec) * * @see AWS spec: http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html * * @todo Consider reusing / converting to TSStringPercentEncode() using a custom map to account for the AWS specific rules. * Currently we don't build a library/archive so we could link with the unit-test binary. Also us

Source from the content-addressed store, hash-verified

79 * @return encoded string.
80 */
81String
82uriEncode(const String &in, bool isObjectName)
83{
84 std::stringstream result;
85
86 for (char i : in) {
87 if (isalnum(i) || i == '-' || i == '_' || i == '.' || i == '~') {
88 /* URI encode every byte except the unreserved characters:
89 * 'A'-'Z', 'a'-'z', '0'-'9', '-', '.', '_', and '~'. */
90 result << i;
91 } else if (i == ' ') {
92 /* The space character is a reserved character and must be encoded as "%20" (and not as "+"). */
93 result << "%20";
94 } else if (isObjectName && i == '/') {
95 /* Encode the forward slash character, '/', everywhere except in the object key name. */
96 result << "/";
97 } else if (i == '+') {
98 /* Only written in the example code, but a plus sign is treated as a space regardless of the position and it must be encoded
99 * as "%20" instead of "%2B" */
100 result << "%20";
101 } else {
102 /* Letters in the hexadecimal value must be upper-case, for example "%1A". */
103 result << "%" << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(i);
104 }
105 }
106
107 return result.str();
108}
109
110/**
111 * @brief checks if the string is URI-encoded (AWS specific encoding version, see spec)

Callers 2

canonicalEncodeFunction · 0.85

Calls 1

strMethod · 0.45

Tested by

no test coverage detected