Jippe Holwerda
04/01/2021, 7:19 PMSinglePageAppRoutingHandler
and ServerFilters.Cors
filter do not play nice together. The CORS OPTION request is being handled by SinglePageAppRoutingHandler
. Since it doesn't match a resource, the fallbackHandler
is used with a new GET request (without headers). When that request is handled by the Cors filter, the Origin header is missing causing the request to fail...Philipp Mayer
04/01/2021, 8:08 PMval server = DebuggingFilters.PrintRequest()
.then(ServerFilters.CatchAll())
.then(ServerFilters.RequestTracing())
.then(CorsFilter)
.then(PowerSocketSwitcherApp(powerSwitch, config.sockets))
.asServer(SunHttp(9090))
.start()
Will let me access it from inside the local network.
But when I swap out SunHttp for Apache, I get a response "not authoritative".
I just found that issue, but it's more centered around the work load it seems: https://github.com/http4k/http4k/issues/481
Btw, my CorsFilter:
val CorsFilter = ServerFilters.Cors(
CorsPolicy(
originPolicy = AllowAllOriginPolicy,
headers = listOf("*"),
methods = Method.values().toList(),
credentials = false
)
)
Do you have any hints?
Thanks in advance!Uberto Barbini
04/09/2021, 8:21 AMVojtěch Knyttl
04/09/2021, 6:34 PMreturning(Status.OK, Body.string(ContentType.TEXT_PLAIN).toLens() to "example string")
mattTea
04/14/2021, 5:05 PM"/path/{param}"
pattern, or is this only possible for contract routes in the "/path" / Path.uuid().of("param")
pattern?
Here’s an example of the contract routing style, where http4k handles type-safety for the path parameter (n.b. using Result4k for error handling in these examples)…
fun getThingRoute(retriever: Retriever) =
"/path" / Path.uuid().of("id") bindContract GET to { id ->
{
retriever(id)
.map { Response(OK).body(it) }
.mapFailure { it.toErrorResponse() }
.get()
}
}
And the non-contract routing pattern I’d like to switch to, but which I think needs our own typesafe error handling (if we want to handle non-UUID path parameters, for example)...
fun getThingRoute(retriever: Retriever) =
"/path/{id}-something-after-param" bind GET to { request ->
resultFrom { UUID.fromString(request.path("id")) }
.mapFailure { NotFound("ID must be a valid UUID") }
.flatMap { id ->
retriever(id)
.map { Response(OK).body(it) }
}
.mapFailure { it.toErrorResponse() }
.get()
}
Thanks!taer
04/22/2021, 10:13 PMRazvan
04/24/2021, 2:38 PMRazvan
04/30/2021, 8:46 AMgetResourceAsStream
is annotated as @nullable
I thought it would say that you can't call .reader()' on its result without
?or
!!`
Companion::class.java.getResourceAsStream("/${resource.removePrefix("/")}").reader()
Paulien van Alst
05/04/2021, 10:59 AMjava.lang.NoSuchMethodError: com.fasterxml.jackson.module.kotlin.KotlinModule
I am using versio 2.10.2
of com.fasterxml.jaclson.module
and version 4.8.0.0
of http4k. How can I fix this?dave
05/07/2021, 8:58 AMelect
05/09/2021, 8:22 AMcurl -X GET -H "Authorization: token $token <https://api.github.com/repos/kotlin-graphics/mary/contents/$path>
I also need to parse the responding json to extract, for example, a sha encoding and create some other json to pass to some other curl
commands. Can http4k be all I need? 😛Andrew O'Hara
05/14/2021, 5:36 PMnull
with both Argo and Jackson. The Swagger Editor seems to treat these as warnings, Swagger UI works fine, but the latest Redoc throws an exception that prevents the UI from loading.
Is there any way to set a non-null description for these parameters? Or has anyone had a better experience with a different version of redoc?s4nchez
05/15/2021, 8:54 AMmavenCentral()
as a repo for plugin dependencies?elect
05/15/2021, 4:00 PMPhilipp Mayer
05/23/2021, 8:35 PMmichaelbannister
05/28/2021, 3:09 PMfun endpoints() = "/orders" bind POST to routes(
"/create" bind ::createOrder named "Create Order",
"/submit" bind ::submitOrder named "Submit Order",
)
object SpanNameFilter {
operator fun invoke(name: String) = Filter { next ->
{ req ->
Span.current().updateName(name)
next(req)
}
}
}
infix fun RoutingHttpHandler.named(name: String) = SpanNameFilter(name).then(this)
Wondered if this might be something you’d be interested in adding to the opentelemetry module in some form or other? Or is there a different way of doing this you’d recommend? Would a more general ability to name RoutingHttpHandlers be useful?Simon Hilz
05/31/2021, 8:28 AMPaulien van Alst
05/31/2021, 1:40 PMUriTemplate
was proposing an extension function on String
called trimSlashes
. What is the reason to declare an extension function on the class String? This extension function will be accessible anywhere in your code base for any String you want, however it is very clear that it should only be used for `String`s representing URI`s .
I was curious behind the reason on declaring it on String
and not UriTemplate
for instance.dave
06/11/2021, 6:32 AMRajanS
06/11/2021, 9:46 AMprivate fun client(uri: Uri): HttpHandler =
SetBaseUriFrom(uri)
.then(RateLimit())
.then(OkHttp(okHttpClient(100)))
Note: It’s using the default RateLimitConfig which is documented as By default, handles maximum of 50 requests per 5 seconds.
Here is how we are testing this out:
fun main(){
val timeTaken = measureTimeMillis {
makeMultipleRequests(51, client(Uri.of("<http://localhost:3002/some-url>")))
}
println(timeTaken)
}
I would expect the time taken to be greater than 5 seconds? Is this is how it’s suppose to work?
Running it a few times to get an average it seems to complete in around 2-3 seconds.
Thanks in advances1m0nw1
06/15/2021, 1:13 PMX
yet gives out a null
pointer
public fun main() {
val l: BiDiBodyLens<X> = Body.auto<X>().toLens()
val request: Request = Request(POST, "/").body("null")
val extracted: X = l.extract(request)
print(extracted) // null :shrug:
}
dave
06/16/2021, 4:10 AMhttps://youtu.be/NjoCjupV8HE▾
Razvan
06/20/2021, 1:01 PMCompanion
java.lang.NoSuchFieldError: Companion
at org.http4k.client.OkHttpKt.requestBody(OkHttp.kt:75)
at org.http4k.client.OkHttpKt.asOkHttp(OkHttp.kt:68)
at org.http4k.client.OkHttpKt.access$asOkHttp(OkHttp.kt:1)
at org.http4k.client.OkHttp$invoke$1.invoke(OkHttp.kt:38)
at org.http4k.client.OkHttp$invoke$1.invoke(OkHttp.kt:35)
It’s the basic client, nothing fancy OkHtttp()
if I replace that with JavaHttpClient() or ApacheClient() all works.
Does that ring a bel or should try to make test projects to show it ?
The error line is the if line in this function
private fun Request.requestBody() =
if (permitsRequestBody(method.toString())) body.payload.array().toRequestBody()
else null
Mervyn McCreight
06/22/2021, 6:53 AMdave
06/22/2021, 3:07 PMhttps://youtu.be/mPmUjJhdYME▾
Razvan
07/04/2021, 5:27 PMlogs.html:1 Access to resource at '<http://localhost:8080/logsse>' from origin '<http://localhost:8880>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Couldn't figure out how to set that header...christophsturm
07/08/2021, 8:21 AMStefan
07/08/2021, 12:56 PMStefan
07/08/2021, 3:32 PMRiku
07/09/2021, 11:41 AMcore.with
. No big deal for me, I am fine at 1.4.32 but I wondered if that issue was on your radar.Riku
07/09/2021, 11:41 AMcore.with
. No big deal for me, I am fine at 1.4.32 but I wondered if that issue was on your radar.***** RESPONSE FAILED to GET: /api/v1/courses *****
java.lang.NullPointerException: Parameter specified as non-null is null: method org.http4k.core.HttpKt.with, parameter $this$with
at org.http4k.core.HttpKt.with(http.kt)
at org.http4k.filter.ServerFilters$Cors$invoke$1$1.invoke(ServerFilters.kt:64)
at org.http4k.filter.ServerFilters$Cors$invoke$1$1.invoke(ServerFilters.kt:50)
at org.http4k.contract.ContractRoutingHttpHandler$identify$1$1$1.invoke(ContractRoutingHttpHandler.kt:105)
at org.http4k.contract.ContractRoutingHttpHandler$identify$1$1$1.invoke(ContractRoutingHttpHandler.kt:26)
at org.http4k.core.Http4kKt$then$2.invoke(Http4k.kt:15)
at org.http4k.core.Http4kKt$then$2.invoke(Http4k.kt)
at org.http4k.routing.RouterMatch$MatchingHandler.invoke(Router.kt:47)
at org.http4k.routing.RouterMatch$MatchingHandler.invoke(Router.kt:46)
at org.http4k.routing.RouterBasedHttpHandler.invoke(RouterBasedHttpHandler.kt:23)
at org.http4k.routing.RouterBasedHttpHandler.invoke(RouterBasedHttpHandler.kt:13)
at org.http4k.filter.ServerFilters$CatchLensFailure$2$1.invoke(ServerFilters.kt:237)
at org.http4k.filter.ServerFilters$CatchLensFailure$2$1.invoke(ServerFilters.kt:45)
at fi.danceupacademy.auth.TokenAuthentication$tokenFilter$1$1.invoke(TokenAuthentication.kt:91)
at fi.danceupacademy.auth.TokenAuthentication$tokenFilter$1$1.invoke(TokenAuthentication.kt:76)
at org.http4k.filter.ServerFilters$Cors$invoke$1$1.invoke(ServerFilters.kt:55)
at org.http4k.filter.ServerFilters$Cors$invoke$1$1.invoke(ServerFilters.kt:50)
at fi.danceupacademy.DanceUpAdminKt$httoRedirectFilter$1$1.invoke(DanceUpAdmin.kt:60)
at fi.danceupacademy.DanceUpAdminKt$httoRedirectFilter$1$1.invoke(DanceUpAdmin.kt:52)
at org.http4k.filter.DebuggingFilters$PrintResponse$invoke$1$1.invoke(DebuggingFilters.kt:31)
at org.http4k.filter.DebuggingFilters$PrintResponse$invoke$1$1.invoke(DebuggingFilters.kt:27)
at org.http4k.filter.RequestFilters$Tap$invoke$1$1.invoke(RequestFilters.kt:23)
at org.http4k.filter.RequestFilters$Tap$invoke$1$1.invoke(RequestFilters.kt:19)
at org.http4k.filter.ServerFilters$InitialiseRequestContext$invoke$1$1.invoke(ServerFilters.kt:311)
at org.http4k.filter.ServerFilters$InitialiseRequestContext$invoke$1$1.invoke(ServerFilters.kt:306)
at org.http4k.core.Http4kKt$then$2.invoke(Http4k.kt:15)
at org.http4k.core.Http4kKt$then$2.invoke(Http4k.kt)
at org.http4k.filter.ServerFilters$CatchAll$invoke$1$1.invoke(ServerFilters.kt:256)
at org.http4k.filter.ServerFilters$CatchAll$invoke$1$1.invoke(ServerFilters.kt:252)
at org.http4k.core.Http4kKt$then$2.invoke(Http4k.kt:15)
at org.http4k.core.Http4kKt$then$2.invoke(Http4k.kt)
at org.http4k.server.Http4kUndertowHttpHandler.handleRequest(Http4kUndertowHttpHandler.kt:37)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1423)
at java.base/java.lang.Thread.run(Thread.java:834)
dave
07/09/2021, 11:56 AMRiku
07/09/2021, 11:56 AMdave
07/09/2021, 1:11 PMRiku
07/09/2021, 1:38 PM