mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 08:09:43 -05:00
fix(apigateway): answer an HTTP API proxy result without a Content-Type as text/plain (#6201)
* fix(apigateway): answer an HTTP API proxy result without a Content-Type as text/plain Measured on AWS (eu-west-1, 2026-10-19): an HTTP API answers a Lambda proxy result that carries a body and no Content-Type header of its own with text/plain; charset=utf-8, in both payload formats. Floci fell back to application/json, the REST API's default, so a client that trusts the header read a plain body as JSON. The fallback now follows the API kind: an HTTP API answers text/plain, a REST API keeps answering application/json. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * test(apigateway): fold the Content-Type cases into the inference test The three cases repeated the inference test's setup, route helper and cleanup, so they join it: two results without a Content-Type in the two payload formats, and one that names application/json. The docs say a statusCode and a body, since a format 2.0 result without a statusCode still takes the inferred JSON path, and the compatibility test's get helper and parameterized name are back on one line each. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> --------- Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
b58947c70a
commit
34f592f7e7
5 files changed
+98
-7
No files matched your search
+18
-1
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.apigatewayv2.ApiGatewayV2Client;
|
||||
import software.amazon.awssdk.services.apigatewayv2.model.IntegrationType;
|
||||
@@ -28,7 +29,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* {"message":"Internal Server Error"}; a statusCode given as text that spells one is taken; format
|
||||
* 2.0 takes a result without a statusCode as a 200 whose body is the result itself. A body that is
|
||||
* an object, one said to be base64 that is not, and an isBase64Encoded of "yes" are answered 500
|
||||
* too, while "True" is read as true.
|
||||
* too, while "True" is read as true. A result with a body and no Content-Type header of its own is
|
||||
* answered text/plain; charset=utf-8.
|
||||
*/
|
||||
@DisplayName("API Gateway V2 Lambda proxy responses")
|
||||
class ApiGatewayV2LambdaProxyResponseTest {
|
||||
@@ -128,6 +130,21 @@ class ApiGatewayV2LambdaProxyResponseTest {
|
||||
assertThat(response.body()).isEqualTo(body);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "payload {0}")
|
||||
@ValueSource(strings = {"1.0", "2.0"})
|
||||
void aResultWithoutAContentTypeIsAnsweredAsTextPlain(String format) throws Exception {
|
||||
// Measured on AWS (eu-west-1, 2026-10-19): a result with a statusCode and a body but no
|
||||
// Content-Type header of its own is answered text/plain; charset=utf-8, in both formats.
|
||||
HttpResponse<String> response = get(format, "ok");
|
||||
|
||||
assertThat(response.statusCode()).isEqualTo(200);
|
||||
assertThat(response.headers().firstValue("Content-Type"))
|
||||
.hasValueSatisfying(contentType -> {
|
||||
assertThat(contentType).startsWith("text/plain");
|
||||
assertThat(contentType.toLowerCase()).contains("charset=utf-8");
|
||||
});
|
||||
}
|
||||
|
||||
private static HttpResponse<String> get(String format, String mode) throws IOException {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(TestFixtures.endpoint() + "/execute-api/" + apiId + "/" + STAGE + "/v"
|
||||
|
||||
Reference in new issue
Block a user