https://kotlinlang.org logo
#http4k
Title
# http4k
p

Philipp Mayer

04/01/2021, 8:08 PM
Hey guys, not sure if I'm missing something, but I ran into a weird issue with the Apache Backend. Setting up my server with
Copy code
val 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:
Copy code
val CorsFilter = ServerFilters.Cors(
        CorsPolicy(
            originPolicy = AllowAllOriginPolicy,
            headers = listOf("*"),
            methods = Method.values().toList(),
            credentials = false
        )
    )
Do you have any hints? Thanks in advance!
s

s4nchez

04/01/2021, 8:57 PM
I couldn't reproduce, at least not with my adapted example:
Copy code
import org.http4k.client.JavaHttpClient
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.core.then
import org.http4k.filter.CorsPolicy
import org.http4k.filter.DebuggingFilters
import org.http4k.filter.ServerFilters
import org.http4k.server.ApacheServer
import org.http4k.server.asServer

fun main() {
    DebuggingFilters.PrintRequest()
        .then(ServerFilters.CatchAll())
        .then(ServerFilters.RequestTracing())
        .then(ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive))
        .then { Response(Status.OK) }
        .asServer(ApacheServer(9090)).start().use {
            val client = JavaHttpClient()
            println(client(Request(Method.GET, "<http://localhost:9090>")))
        }
}
Can you please try that and let us know if we're missing something?
p

Philipp Mayer

04/02/2021, 3:53 PM
That's working and my tests are working too. But as soon as my client has a different IP (e.g. calling the service from my smartphone) I get the mentioned error.
I thought it must have something to do with my network, but the error doesn't appear when I switch Apache for SunHttp.
r

Razvan

04/03/2021, 10:16 AM
Not sure that it helps but I also had a problem accessing localhost in cloudfoundry with apache server https://kotlinlang.slack.com/archives/C5AL3AKUY/p1602518040044800 I gave up and switched to Undertow.
4 Views