AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
RecursionDetection.h
1
6#pragma once
7
8#include <aws/core/platform/Environment.h>
9#include <aws/core/http/HttpRequest.h>
10#include <iomanip>
11
12namespace smithy
13{
14 namespace client
15 {
16 static const char SMITHY_AWS_LAMBDA_FUNCTION_NAME[] = "AWS_LAMBDA_FUNCTION_NAME";
17 static const char SMITHY_X_AMZN_TRACE_ID[] = "_X_AMZN_TRACE_ID";
18
20 {
21 public:
22 static void AppendRecursionDetectionHeader(const std::shared_ptr<Aws::Http::HttpRequest>& ioRequest)
23 {
24 if (!ioRequest || ioRequest->HasHeader(Aws::Http::X_AMZN_TRACE_ID_HEADER))
25 {
26 return;
27 }
29 if (awsLambdaFunctionName.empty())
30 {
31 return;
32 }
34 if (xAmznTraceIdVal.empty())
35 {
36 return;
37 }
38
39 // Escape all non-printable ASCII characters by percent encoding
40 Aws::OStringStream xAmznTraceIdValEncodedStr;
41 for (const char ch : xAmznTraceIdVal)
42 {
43 if (ch >= 0x20 && ch <= 0x7e) // ascii chars [32-126] or [' ' to '~'] are not escaped
44 {
45 xAmznTraceIdValEncodedStr << ch;
46 }
47 else
48 {
49 // A percent-encoded octet is encoded as a character triplet
50 xAmznTraceIdValEncodedStr << '%' // consisting of the percent character "%"
51 << std::hex << std::setfill('0') << std::setw(2) << std::uppercase
52 << (size_t)ch
53 //followed by the two hexadecimal digits representing that octet's numeric value
54 << std::dec << std::setfill(' ') << std::setw(0) << std::nouppercase;
55 }
56 }
57 xAmznTraceIdVal = xAmznTraceIdValEncodedStr.str();
58
59 ioRequest->SetHeaderValue(Aws::Http::X_AMZN_TRACE_ID_HEADER, xAmznTraceIdVal);
60 }
61 };
62 }
63}
static void AppendRecursionDetectionHeader(const std::shared_ptr< Aws::Http::HttpRequest > &ioRequest)
AWS_CORE_API Aws::String GetEnv(const char *name)
AWS_CORE_API const char X_AMZN_TRACE_ID_HEADER[]
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::basic_ostringstream< char, std::char_traits< char >, Aws::Allocator< char > > OStringStream
static const char SMITHY_AWS_LAMBDA_FUNCTION_NAME[]
static const char SMITHY_X_AMZN_TRACE_ID[]