Repository: quarkusio/quarkus
Issue: Last-Modified response header is not properly handled in QuarkusTests using MockHttpEventServer

### Describe the bug

I am using RestAssured in a QuarkusTest to test a RestEasy resource endpoint that returns a response containing the header:

`Last-Modified: Tue, 26 Oct 2021 01:01:01 GMT` 

The test goes as follows:
```
@Test
void verifyLastModifiedHeader() {
        RestAssured.given()
                .accept(JSON)
                .when()
                .get("/my-endpoint")
                .then()
                .statusCode(200)
                .header("Last-Modified", "Tue, 26 Oct 2021 01:01:01 GMT");
}
```

The test fails with the following output:

> java.lang.AssertionError: 1 expectation failed.
Expected header "Last-Modified" was not "Tue, 26 Oct 2021 01:01:01 GMT", was "26 Oct 2021 01:01:01 GMT". Headers are:
content-length=84
Access-Control-Allow-Origin=*
Access-Control-Allow-Methods=GET
Last-Modified=Tue
Last-Modified=26 Oct 2021 01:01:01 GMT

This seems to be due to the MockHttpEventServer splitting all response headers on `","`. This is logical for multivalue headers, but for Last-Modified (and other related headers such as If-Modified-Since) this behaviour is incorrect.

### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

openjdk version "17" 2021-09-14

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

2.7.5

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Gradle 7.2

### Additional information

_No response_

Changed files:
extensions/amazon-lambda-http/http-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
extensions/amazon-lambda-rest/rest-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java
extensions/amazon-lambda/event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockEventServer.java

diff --git a/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java b/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java
index 25b9106e7f7..9ee81290fab 100644
--- a/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java
+++ b/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java
@@ -117,8 +117,13 @@ public void processResponse(RoutingContext ctx, RoutingContext pending, Buffer b
                 HttpServerResponse response = pending.response();
                 if (res.getHeaders() != null) {
                     for (Map.Entry<String, String> header : res.getHeaders().entrySet()) {
-                        for (String val : header.getValue().split(",")) {
-                            response.headers().add(header.getKey(), val);
+                        if (canHaveCommaValue(header.getKey())) {
+                            response.headers().add(header.getKey(), header.getValue());
+
+                        } else {
+                            for (String val : header.getValue().split(",")) {
+                                response.headers().add(header.getKey(), val);
+                            }
                         }
                     }
                 }
diff --git a/extensions/amazon-lambda-http/http-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java b/extensions/amazon-lambda-http/http-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
index 83104912800..9a7b50c9a38 100644
--- a/extensions/amazon-lambda-http/http-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
+++ b/extensions/amazon-lambda-http/http-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
@@ -79,4 +79,45 @@ public void testServer() throws Exception {
         Assertions.assertEquals("Hi", lambdaResponse.readEntity(String.class));
         lambdaResponse.close();
     }
+
+    @Test
+    public void testDateHeaders() throws Exception {
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget base = client.target("http://localhost:" + MockEventServer.DEFAULT_PORT);
+        Future<Response> lambdaInvoke = base.request().async()
+                .post(Entity.text("Hello World"));
+
+        Response next = base.path(MockEventServer.NEXT_INVOCATION).request().get();
+        Assertions.assertEquals(200, next.getStatus());
+        String requestId = next.getHeaderString(AmazonLambdaApi.LAMBDA_RUNTIME_AWS_REQUEST_ID);
+        String traceId = next.getHeaderString(AmazonLambdaApi.LAMBDA_TRACE_HEADER_KEY);
+        Assertions.assertNotNull(requestId);
+        Assertions.assertNotNull(traceId);
+        String json = next.readEntity(String.class);
+        APIGatewayV2HTTPEvent event = eventReader.readValue(json);
+        Assertions.assertEquals("text/plain", event.getHeaders().get("Content-Type"));
+        Assertions.assertEquals("Hello World", event.getBody());
+        next.close();
+
+        APIGatewayV2HTTPResponse res = new APIGatewayV2HTTPResponse();
+        res.setStatusCode(201);
+        res.setHeaders(new HashMap());
+        res.getHeaders().put("Content-Type", "text/plain");
+        res.getHeaders().put("Last-Modified", "Tue, 26 Oct 2021 01:01:01 GMT");
+        res.getHeaders().put("Expires", "Tue, 26 Oct 2021 01:01:01 GMT");
+        res.getHeaders().put("Date", "Tue, 26 Oct 2021 01:01:01 GMT");
+        res.setBody("Hi");
+        Response sendResponse = base.path(MockEventServer.INVOCATION).path(requestId).path("response")
+                .request().post(Entity.json(resWriter.writeValueAsString(res)));
+        Assertions.assertEquals(204, sendResponse.getStatus());
+        sendResponse.close();
+
+        Response lambdaResponse = lambdaInvoke.get();
+        Assertions.assertEquals(201, lambdaResponse.getStatus());
+        Assertions.assertEquals("Hi", lambdaResponse.readEntity(String.class));
+        Assertions.assertEquals("Tue, 26 Oct 2021 01:01:01 GMT", lambdaResponse.getStringHeaders().getFirst("Last-Modified"));
+        Assertions.assertEquals("Tue, 26 Oct 2021 01:01:01 GMT", lambdaResponse.getStringHeaders().getFirst("Expires"));
+        Assertions.assertEquals("Tue, 26 Oct 2021 01:01:01 GMT", lambdaResponse.getStringHeaders().getFirst("Date"));
+        lambdaResponse.close();
+    }
 }
diff --git a/extensions/amazon-lambda-rest/rest-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java b/extensions/amazon-lambda-rest/rest-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
index 508ea7e4bba..b5e9cc32502 100644
--- a/extensions/amazon-lambda-rest/rest-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
+++ b/extensions/amazon-lambda-rest/rest-event-server/src/test/java/io/quarkus/amazon/lambda/runtime/EventServerTest.java
@@ -22,6 +22,7 @@
 
 import io.quarkus.amazon.lambda.http.model.AwsProxyRequest;
 import io.quarkus.amazon.lambda.http.model.AwsProxyResponse;
+import io.quarkus.amazon.lambda.http.model.Headers;
 
 public class EventServerTest {
 
@@ -80,4 +81,47 @@ public void testServer() throws Exception {
         Assertions.assertEquals("Hi", lambdaResponse.readEntity(String.class));
         lambdaResponse.close();
     }
+
+    @Test
+    public void testDateHeaders() throws Exception {
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget base = client.target("http://localhost:" + MockEventServer.DEFAULT_PORT);
+        Future<Response> lambdaInvoke = base.request().async()
+                .post(Entity.text("Hello World"));
+
+        Response next = base.path(MockEventServer.NEXT_INVOCATION).request().get();
+        Assertions.assertEquals(200, next.getStatus());
+        String requestId = next.getHeaderString(AmazonLambdaApi.LAMBDA_RUNTIME_AWS_REQUEST_ID);
+        String traceId = next.getHeaderString(AmazonLambdaApi.LAMBDA_TRACE_HEADER_KEY);
+        Assertions.assertNotNull(requestId);
+        Assertions.assertNotNull(traceId);
+        String json = next.readEntity(String.class);
+        AwsProxyRequest event = eventReader.readValue(json);
+        Assertions.assertEquals("text/plain", event.getMultiValueHeaders().getFirst("Content-Type"));
+        Assertions.assertEquals("Hello World", event.getBody());
+        next.close();
+
+        AwsProxyResponse res = new AwsProxyResponse();
+        res.setStatusCode(201);
+        res.setMultiValueHeaders(new Headers());
+        res.getMultiValueHeaders().add("Content-Type", "text/plain");
+        res.getMultiValueHeaders().add("Last-Modified", "Tue, 26 Oct 2021 01:01:01 GMT");
+        res.getMultiValueHeaders().add("Expires", "Tue, 26 Oct 2021 01:01:01 GMT");
+        res.getMultiValueHeaders().add("Date", "Tue, 26 Oct 2021 01:01:01 GMT");
+        res.setBody("Hi");
+        Response sendResponse = base.path(MockEventServer.INVOCATION).path(requestId).path("response")
+                .request().post(Entity.json(resWriter.writeValueAsString(res)));
+        Assertions.assertEquals(204, sendResponse.getStatus());
+        sendResponse.close();
+
+        Response lambdaResponse = lambdaInvoke.get();
+        Assertions.assertEquals(201, lambdaResponse.getStatus());
+        Assertions.assertEquals("Hi", lambdaResponse.readEntity(String.class));
+        Assertions.assertTrue(lambdaResponse.getStringHeaders().containsKey("Content-Type"));
+        Assertions.assertEquals("Tue, 26 Oct 2021 01:01:01 GMT", lambdaResponse.getStringHeaders().getFirst("Last-Modified"));
+        Assertions.assertEquals("Tue, 26 Oct 2021 01:01:01 GMT", lambdaResponse.getStringHeaders().getFirst("Expires"));
+        Assertions.assertEquals("Tue, 26 Oct 2021 01:01:01 GMT", lambdaResponse.getStringHeaders().getFirst("Date"));
+        lambdaResponse.close();
+    }
+
 }
diff --git a/extensions/amazon-lambda/event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockEventServer.java b/extensions/amazon-lambda/event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockEventServer.java
index 5429ea1d805..95330ea6dc2 100644
--- a/extensions/amazon-lambda/event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockEventServer.java
+++ b/extensions/amazon-lambda/event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockEventServer.java
@@ -2,6 +2,9 @@
 
 import java.io.Closeable;
 import java.io.IOException;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
@@ -40,6 +43,21 @@ public class MockEventServer implements Closeable {
     public static final String NEXT_INVOCATION = BASE_PATH + AmazonLambdaApi.API_PATH_INVOCATION_NEXT;
     public static final String POST_EVENT = BASE_PATH;
     public static final String CONTINUE = "100-continue";
+    private static final Set<String> COMMA_VALUE_HEADERS;
+
+    static {
+        COMMA_VALUE_HEADERS = new HashSet<>();
+        COMMA_VALUE_HEADERS.add("date");
+        COMMA_VALUE_HEADERS.add("last-modified");
+        COMMA_VALUE_HEADERS.add("expires");
+        COMMA_VALUE_HEADERS.add("if-modified-since");
+        COMMA_VALUE_HEADERS.add("if-unmodified-since");
+    }
+
+    public static boolean canHaveCommaValue(String header) {
+        return COMMA_VALUE_HEADERS.contains(header.toLowerCase(Locale.ROOT));
+    }
+
     final AtomicBoolean closed = new AtomicBoolean();
 
     public MockEventServer() {