Ensure user set headers in API Gateway are properly propagated to message headers

This commit is contained in:
Oleg Zhurakousky
2021-05-18 16:33:04 +02:00
parent 25387b83be
commit c07aa97d15
2 changed files with 25 additions and 75 deletions

View File

@@ -121,6 +121,12 @@ final class AWSLambdaUtils {
messageBuilder = MessageBuilder.withPayload(body).copyHeaders(requestMap); messageBuilder = MessageBuilder.withPayload(body).copyHeaders(requestMap);
} }
} }
Object providedHeaders = requestMap.remove("headers");
if (providedHeaders != null && providedHeaders instanceof Map) {
messageBuilder.removeHeader("headers");
messageBuilder.copyHeaders((Map<String, Object>) providedHeaders);
}
} }
else if (request instanceof Iterable) { else if (request instanceof Iterable) {
messageBuilder = MessageBuilder.withPayload(request); messageBuilder = MessageBuilder.withPayload(request);
@@ -131,6 +137,8 @@ final class AWSLambdaUtils {
if (awsContext != null) { if (awsContext != null) {
messageBuilder.setHeader("aws-context", awsContext); messageBuilder.setHeader("aws-context", awsContext);
} }
logger.info("Incoming request headers: " + headers);
return messageBuilder.copyHeaders(headers).build(); return messageBuilder.copyHeaders(headers).build();
} }

View File

@@ -45,17 +45,17 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <!-- <dependency> -->
<groupId>org.awaitility</groupId> <!-- <groupId>org.awaitility</groupId> -->
<artifactId>awaitility</artifactId> <!-- <artifactId>awaitility</artifactId> -->
<scope>test</scope> <!-- <scope>test</scope> -->
</dependency> <!-- </dependency> -->
<dependency> <!-- <dependency> -->
<groupId>org.testcontainers</groupId> <!-- <groupId>org.testcontainers</groupId> -->
<artifactId>testcontainers</artifactId> <!-- <artifactId>testcontainers</artifactId> -->
<version>1.14.3</version> <!-- <version>1.14.3</version> -->
<scope>test</scope> <!-- <scope>test</scope> -->
</dependency> <!-- </dependency> -->
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
@@ -74,11 +74,11 @@
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <!-- <configuration> -->
<excludes> <!-- <excludes> -->
<exclude>com/example/ContainerTests.java</exclude> <!-- <exclude>com/example/ContainerTests.java</exclude> -->
</excludes> <!-- </excludes> -->
</configuration> <!-- </configuration> -->
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@@ -149,62 +149,4 @@
</profile> </profile>
</profiles> </profiles>
<!-- <repositories> -->
<!-- <repository> -->
<!-- <id>spring-snapshots</id> -->
<!-- <name>Spring Snapshots</name> -->
<!-- <url>https://repo.spring.io/libs-snapshot-local</url> -->
<!-- <snapshots> -->
<!-- <enabled>true</enabled> -->
<!-- </snapshots> -->
<!-- <releases> -->
<!-- <enabled>false</enabled> -->
<!-- </releases> -->
<!-- </repository> -->
<!-- <repository> -->
<!-- <id>spring-milestones</id> -->
<!-- <name>Spring Milestones</name> -->
<!-- <url>https://repo.spring.io/libs-milestone-local</url> -->
<!-- <snapshots> -->
<!-- <enabled>false</enabled> -->
<!-- </snapshots> -->
<!-- </repository> -->
<!-- <repository> -->
<!-- <id>spring-releases</id> -->
<!-- <name>Spring Releases</name> -->
<!-- <url>https://repo.spring.io/release</url> -->
<!-- <snapshots> -->
<!-- <enabled>false</enabled> -->
<!-- </snapshots> -->
<!-- </repository> -->
<!-- </repositories> -->
<!-- <pluginRepositories> -->
<!-- <pluginRepository> -->
<!-- <id>spring-snapshots</id> -->
<!-- <name>Spring Snapshots</name> -->
<!-- <url>https://repo.spring.io/libs-snapshot-local</url> -->
<!-- <snapshots> -->
<!-- <enabled>true</enabled> -->
<!-- </snapshots> -->
<!-- <releases> -->
<!-- <enabled>false</enabled> -->
<!-- </releases> -->
<!-- </pluginRepository> -->
<!-- <pluginRepository> -->
<!-- <id>spring-milestones</id> -->
<!-- <name>Spring Milestones</name> -->
<!-- <url>https://repo.spring.io/libs-milestone-local</url> -->
<!-- <snapshots> -->
<!-- <enabled>false</enabled> -->
<!-- </snapshots> -->
<!-- </pluginRepository> -->
<!-- <pluginRepository> -->
<!-- <id>spring-releases</id> -->
<!-- <name>Spring Releases</name> -->
<!-- <url>https://repo.spring.io/libs-release-local</url> -->
<!-- <snapshots> -->
<!-- <enabled>false</enabled> -->
<!-- </snapshots> -->
<!-- </pluginRepository> -->
<!-- </pluginRepositories> -->
</project> </project>