Igor Urisman
Igor Urisman

Reputation: 798

Obtain version of Akka HTTP at run time

My server is built on top of Akka HTTP. If I don't set the Server header, the externally configurable default of akka-http/10.1.8 will be automatically added by Akka. I know how to override that with my own server by adding the respondWithHeaders directive around my entire routs tree:

   respondWithHeaders(Server(myProductVersion)) {
      // my routs here
   }

This works as expected; the Server response header now reads my product. What I want though is to include akka's header as well, as I like it and don't mind telling the world about my server stack. Given the signature of the Server.apply method, I should be able to do that like so:

   respondWithHeaders(Server(myProductVersion, akkaProductVersion)) {
      // my routs here
   }

... my problem is that I can't figure out how to get at that akkaProductVersion object!

Upvotes: 4

Views: 226

Answers (1)

Mario Galic
Mario Galic

Reputation: 48420

Try reading akka.http.version configuration property like so

system.settings.config.getString("akka.http.version")

so you could try

Server(
  myProductVersion, 
  system.settings.config.getString("akka.http.version")
)

According to default configuration

    # The default value of the `Server` header to produce if no
    # explicit `Server`-header was included in a response.
    # If this value is the empty string and no header was included in
    # the request, no `Server` header will be rendered at all.
    server-header = akka-http/${akka.http.version}

We can see how akka-http reads server-header when constructing ServerSettings here:

c.getString("server-header").toOption.map(Server(_)),

Upvotes: 1

Related Questions