Finatra, for some reason, I don't want to expose this part of informati..." /> Finatra, for some reason, I don't want to expose this part of informati..." /> Finatra, for some reason, I don't want to expose this part of informati..."/>

modify Finatra response header

113 views Asked by At

Finatra returns framework's name by default in response header as "Server" -> Finatra,

for some reason, I don't want to expose this part of information.

Is there anyway to modify it? I have tried filters and response.ok.header.set. but no luck.

thanks all.

Server header information:

server header information

1

There are 1 answers

0
Mustafa Simav On

Finatra sets Server header in com.twitter.finatra.http.filters.HttpResponseFilter. You may use HttpResponseFilter directly or via CommonFilters.

If you want to override this behavior, I suggest defining a new Filter like this

@Singleton
class CustomServerNameFilter extends SimpleFilter[Request, Response] {
  def apply(request: Request, service: Service[Request, Response]): Future[Response] =
    service(request).map { response =>
      response.headerMap.set(HttpHeaders.Server, "My Custom Server")
      response
    }
}

And using it before HttpResponseFilter or CommonFilters like

class MyFinatraServer extends HttpServer {

  override protected def configureHttp(router: HttpRouter): Unit =
    router
      .filter[CustomServerNameFilter]
      .filter[CommonFilters]
      .add[MyController]

}