Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lamba Proxy does not populate response headers correctly #1330

Open
sdelamo opened this issue Apr 1, 2022 · 0 comments · May be fixed by #1338
Open

Lamba Proxy does not populate response headers correctly #1330

sdelamo opened this issue Apr 1, 2022 · 0 comments · May be fixed by #1338
Labels
type: bug Something isn't working
Milestone

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Apr 1, 2022

In an Application with the netty runtime the following test passes:

package com.example

import io.micronaut.context.annotation.Property
import io.micronaut.context.annotation.Requires
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Status
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import spock.lang.Specification

@Property(name = 'spec.name', value = 'ContentTypeSpec')
@MicronautTest
class ContentTypeSpec extends Specification {

    @Inject
    @Client("/")
    HttpClient httpClient

    void "verify controllers return json by default"() {
        given:
        HttpRequest<?> request = HttpRequest._GET_('/json/bydefault').accept(MediaType.APPLICATION_JSON)

        when:
        HttpResponse<String> response = httpClient.toBlocking().exchange(request, String)

        then:
        HttpStatus._OK_ == response.status()
        response.body.get() == '{"msg":"Hello world"}'
        response.headers
        "application/json" == response.headers.get("Content-Type")
    }

    @Controller('/json')
    @Requires(property = 'spec.name', value = 'ContentTypeSpec')
    static class BodyController {

        @Get("/bydefault")
        @Status(HttpStatus.OK)
        Map<String, Object> index() {
            [msg: "Hello world"]
        }
    }
}

However, an Application with lambda runtime the following tests fails:

package com.example

import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder
import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext
import com.amazonaws.serverless.proxy.model.AwsProxyRequest
import com.amazonaws.serverless.proxy.model.AwsProxyResponse
import com.amazonaws.services.lambda.runtime.Context
import io.micronaut.function.aws.proxy.MicronautLambdaHandler
import io.micronaut.http.HttpHeaders
import io.micronaut.http.HttpMethod
import io.micronaut.http.HttpStatus
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Status
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class ContentTypeWithoutMicronautTestSpec extends Specification {
    @Shared
    @AutoCleanup
    MicronautLambdaHandler handler = new MicronautLambdaHandler()

    @Shared
    Context lambdaContext = new MockLambdaContext()

    void "verify controllers return json by default"() {
        given:
        AwsProxyRequest request = new AwsProxyRequestBuilder("/json/isthedefault", HttpMethod.GET.toString())
                .header(HttpHeaders.ACCEPT,  MediaType.APPLICATION_JSON)
                .build()

        when:
        AwsProxyResponse response = handler.handleRequest(request, lambdaContext)

        then:
        HttpStatus._OK_.code == response.statusCode
        response.body == '{"msg":"Hello world"}'
        response.headers
        "application/json" == response.headers.get("Content-Type")
    }

    @Controller('/json')
    static class JsonIsTheDefaultController {

        @Get("/isthedefault")
        @Status(HttpStatus._OK_)
        Map<String, Object> index() {
            [msg: "Hello world"]
        }
    }
}

With headers being null in the response.

@sdelamo sdelamo added the type: bug Something isn't working label Apr 1, 2022
@sdelamo sdelamo added this to the 3.2.2 milestone Apr 1, 2022
sdelamo added a commit that referenced this issue Apr 1, 2022
sdelamo added a commit that referenced this issue Apr 4, 2022
@sdelamo sdelamo linked a pull request Apr 4, 2022 that will close this issue
@timyates timyates removed their assignment May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
2 participants