diff --git a/build.gradle b/build.gradle index e324c075b..c2de71324 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ allprojects { group 'com.agorapulse' - version micronautVersion + version "${micronautVersion}.1" repositories { jcenter() diff --git a/micronaut-function-aws-agp/src/main/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequest.java b/micronaut-function-aws-agp/src/main/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequest.java index fdea838b5..f88cee137 100644 --- a/micronaut-function-aws-agp/src/main/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequest.java +++ b/micronaut-function-aws-agp/src/main/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequest.java @@ -16,6 +16,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.util.*; +import java.util.regex.Pattern; abstract class ApiGatewayProxyHttpRequest implements HttpRequest { @@ -145,7 +146,9 @@ public Collection values() { remoteAddress = new InetSocketAddress(identity.getSourceIp(), HTTPS_PORT); - MutableHttpRequest request = HttpRequest.create(this.method, "https://" + serverName + input.getPath()); + MutableHttpRequest request = HttpRequest.create(this.method, + "https://" + serverName + reconstructPath(Optional.ofNullable(input.getResource()).orElse(input.getPath()), input.getPathParameters()) + ); this.uri = request.getUri(); @@ -197,4 +200,15 @@ public MutableConvertibleValues getAttributes() { public String toString() { return getClass().getSimpleName() + ": " + input.toString(); } + + static String reconstructPath(String resource, Map pathVariables) { + if (pathVariables == null) { + return resource; + } + String path = resource; + for (Map.Entry variable : pathVariables.entrySet()) { + path = path.replaceAll("\\{" + Pattern.quote(variable.getKey()) +"\\+?}", variable.getValue()); + } + return path; + } } diff --git a/micronaut-function-aws-agp/src/test/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequestSpec.groovy b/micronaut-function-aws-agp/src/test/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequestSpec.groovy index 719fd0360..c4d59546c 100644 --- a/micronaut-function-aws-agp/src/test/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequestSpec.groovy +++ b/micronaut-function-aws-agp/src/test/groovy/com/agorapulse/micronaut/agp/ApiGatewayProxyHttpRequestSpec.groovy @@ -4,6 +4,7 @@ import com.agorapulse.gru.Gru import com.agorapulse.gru.agp.ApiGatewayProxy import com.agorapulse.micronaut.http.server.tck.AbstractApiGatewayProxyHttpRequestSpec import org.junit.Rule +import spock.lang.Unroll class ApiGatewayProxyHttpRequestSpec extends AbstractApiGatewayProxyHttpRequestSpec { @@ -16,4 +17,15 @@ class ApiGatewayProxyHttpRequestSpec extends AbstractApiGatewayProxyHttpRequestS map '/hello/mfa' to ApiGatewayProxyHandler }) + @Unroll + void 'test reconstruct path #path with variable #variables to #original'() { + expect: + ApiGatewayProxyHttpRequest.reconstructPath(resource, variables) == original + where: + original | resource | variables + '/foo/bar' | '/foo/bar' | null + '/foo/bar' | '/foo/{place}' | [place: 'bar'] + '/foo/bar' | '/{proxy+}' | [proxy: 'foo/bar'] + } + }