Search code examples
scalaplayframeworklagom

How should I access requested host in a Lagom service?


I have a Lagom ServerServiceCall, which gives me access to Lagom's RequestHeader containing information about the requested URI (path) and the message protocol (media type).

What I'd really like, however, is to find the 'host' and protocol which the client requested. In a standard Play application it looks like this data is in the 'host' and 'proto' fields of the RequestHeader, but the Lagom version of RequestHeader doesn't contain those fields. I can go poking around in the header values themselves for Host and / or various X-Forwarded-... headers but perhaps there's a better way?


Solution

  • Lagom will let you read the headers from a request like you already described but the actual header where the information you want is located will depend on the API Gateway you deploy.

    For instance, in developer mode Lagom starts an API Gateway that currently doesn't add X-Forwarded-... info, but when you deploy in production your HAProxy gateway could keep that information.

    Lagom doesn't set any convention or restriction.