diff --git a/serverless/serverless_http_google/src/main/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapter.kt b/serverless/serverless_http_google/src/main/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapter.kt index f92cd0445a..ef35490ef8 100644 --- a/serverless/serverless_http_google/src/main/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapter.kt +++ b/serverless/serverless_http_google/src/main/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapter.kt @@ -22,24 +22,26 @@ class GoogleServerlessHttpAdapter(private val handler: HttpHandler): HttpFunctio val qp = request.queryParameters?.map { (k, v) -> QueryParameter(k, v) } ?: emptyList() val h = request.headers?.map { (k, v) -> Header(k, v) } ?: emptyList() - request.parts.map { (k, v) -> - HttpPart( - name = k, - body = v.inputStream.readAllBytes(), - headers = Headers(), - contentType = v.contentType?.map { parseContentType(it) }?.orElse(null), - size = v.contentLength, - submittedFileName = v.fileName.orElse(null), + if (request.contentType.orElse("").contains("multipart")) { + request.parts.map { (k, v) -> + HttpPart( + name = k, + body = v.inputStream.readAllBytes(), + headers = Headers(), + contentType = v.contentType?.map { parseContentType(it) }?.orElse(null), + size = v.contentLength, + submittedFileName = v.fileName.orElse(null), - /* - name: String, - body: Any, - headers: Headers = Headers(), - contentType: ContentType? = null, - size: Long = -1L, - submittedFileName: String? = null - */ - ) + /* + name: String, + body: Any, + headers: Headers = Headers(), + contentType: ContentType? = null, + size: Long = -1L, + submittedFileName: String? = null + */ + ) + } } return HttpRequest( diff --git a/serverless/serverless_http_google/src/test/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapterTest.kt b/serverless/serverless_http_google/src/test/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapterTest.kt index 0cdf8c4ea3..c805e7e9ff 100644 --- a/serverless/serverless_http_google/src/test/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapterTest.kt +++ b/serverless/serverless_http_google/src/test/kotlin/com/hexagontk/serverless/http/google/GoogleServerlessHttpAdapterTest.kt @@ -1,34 +1,36 @@ package com.hexagontk.serverless.http.google import com.google.cloud.functions.HttpFunction -import com.google.cloud.functions.HttpRequest -import com.google.cloud.functions.HttpResponse import com.google.cloud.functions.invoker.runner.Invoker import com.hexagontk.core.freePort import com.hexagontk.core.urlOf import com.hexagontk.http.client.HttpClient import com.hexagontk.http.client.HttpClientSettings import com.hexagontk.http.client.java.JavaClientAdapter +import com.hexagontk.http.handlers.Get import kotlin.reflect.KClass import kotlin.test.Test import kotlin.test.assertEquals internal class GoogleServerlessHttpAdapterTest { - class TestServerlessHttpAdapter: HttpFunction { - override fun service(request: HttpRequest, response: HttpResponse) { - response.writer.write("Hello World!") - } - } + class TestServerlessHttpAdapter: HttpFunction by GoogleServerlessHttpAdapter( + Get { ok("Hello World!") } + ) @Test fun `Google functions work ok`() { + val client = invoker(TestServerlessHttpAdapter::class) + assertEquals("Hello World!", client.get().bodyString()) + } + + private fun invoker(function: KClass<*>): HttpClient { val port = freePort() val baseUrl = urlOf("http://localhost:${port}") val client = HttpClient(JavaClientAdapter(), HttpClientSettings(baseUrl)) - invoker(port, TestServerlessHttpAdapter::class) + invoker(port, function) client.start() - assertEquals("Hello World!", client.get().bodyString()) + return client } private fun invoker(port: Int, function: KClass<*>): Invoker {