Skip to content

Commit 26de24e

Browse files
Merge pull request #122 from awslabs/API-GatewayAcceptSupport
Added support for accept header for api-gateway clients. Updated http…
2 parents 9ab7d22 + de9b180 commit 26de24e

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,26 @@ WinHttpSyncHttpClient::~WinHttpSyncHttpClient()
122122

123123
void* WinHttpSyncHttpClient::OpenRequest(const Aws::Http::HttpRequest& request, void* connection, const Aws::StringStream& ss) const
124124
{
125+
LPCWSTR accept[2] = { nullptr, nullptr };
125126

126127
DWORD requestFlags = WINHTTP_FLAG_REFRESH |
127128
(request.GetUri().GetScheme() == Scheme::HTTPS ? WINHTTP_FLAG_SECURE : 0);
128129

129-
static LPCWSTR accept[2] = { L"*/*", nullptr };
130+
Aws::WString acceptHeader(L"*/*");
131+
132+
if (request.HasHeader(Aws::Http::ACCEPT_HEADER))
133+
{
134+
acceptHeader = Aws::Utils::StringUtils::ToWString(request.GetHeaderValue(Aws::Http::ACCEPT_HEADER).c_str());
135+
}
136+
137+
accept[0] = acceptHeader.c_str();
130138

131139
Aws::WString wss = StringUtils::ToWString(ss.str().c_str());
132140

133141
HINTERNET hHttpRequest = WinHttpOpenRequest(connection, StringUtils::ToWString(HttpMethodMapper::GetNameForHttpMethod(request.GetMethod())).c_str(),
134142
wss.c_str(), nullptr, nullptr, accept, requestFlags);
135143

136-
//DISABLE_FEATURE settings need to be made after OpenRequest but before SendRequest
144+
//DISABLE_FEATURE settings need to be made after OpenRequest but before SendRequest
137145
if (!m_allowRedirects)
138146
{
139147
requestFlags = WINHTTP_DISABLE_REDIRECTS;

aws-cpp-sdk-core/source/http/windows/WinINetSyncHttpClient.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ void* WinINetSyncHttpClient::OpenRequest(const Aws::Http::HttpRequest& request,
111111
INTERNET_FLAG_NO_CACHE_WRITE |
112112
(m_allowRedirects ? 0 : INTERNET_FLAG_NO_AUTO_REDIRECT);
113113

114-
static LPCSTR accept[2] = { "*/*", nullptr };
114+
LPCSTR accept[2] = { nullptr, nullptr };
115+
116+
Aws::String acceptHeader("*/*");
117+
118+
if (request.HasHeader(Aws::Http::ACCEPT_HEADER))
119+
{
120+
acceptHeader = request.GetHeaderValue(Aws::Http::ACCEPT_HEADER);
121+
}
122+
123+
accept[0] = acceptHeader.c_str();
124+
115125
HINTERNET hHttpRequest = HttpOpenRequestA(connection, HttpMethodMapper::GetNameForHttpMethod(request.GetMethod()),
116126
ss.str().c_str(), nullptr, nullptr, accept, requestFlags, 0);
117127
AWS_LOGSTREAM_DEBUG(GetLogTag(), "HttpOpenRequestA returned handle " << hHttpRequest);

code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/Metadata.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ public class Metadata {
3434
private String protocol;
3535
private String projectName;
3636
private String classNamePrefix;
37+
private String acceptHeader;
3738
private Map<String, String> additionalHeaders;
3839
}

code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/generators/cpp/apigateway/APIGatewayRestJsonCppClientGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public APIGatewayRestJsonCppClientGenerator() throws Exception {
3333

3434
public SdkFileEntry[] generateSourceFiles(ServiceModel serviceModel) throws Exception {
3535

36+
serviceModel.getMetadata().setAcceptHeader("application/json");
37+
3638
Shape invokeMethodRequest = serviceModel.getShapes().get("TestInvokeMethodRequest");
3739
Map<String, ShapeMember> members = invokeMethodRequest.getMembers();
3840

code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/AbstractServiceRequest.vm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace ${metadata.namespace}
2929
if(headers.size() == 0 || (headers.size() > 0 && headers.count(Aws::Http::CONTENT_TYPE_HEADER) == 0))
3030
{
3131
headers.insert(Aws::Http::HeaderValuePair(Aws::Http::CONTENT_TYPE_HEADER, ${CppViewHelper.computeRequestContentType($metadata)} ));
32+
#if($metadata.acceptHeader)
33+
headers.insert(Aws::Http::HeaderValuePair(Aws::Http::ACCEPT_HEADER, "${metadata.acceptHeader}"));
34+
#end
3235
}
3336

3437
#if($metadata.additionalHeaders)

0 commit comments

Comments
 (0)