Created
February 20, 2016 02:31
-
-
Save sirsavary/a8b90b1577ebdb8971f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import play.api.mvc.EssentialFilter; | |
| import play.http.HttpFilters; | |
| import util.HostFilter; | |
| import javax.inject.Inject; | |
| public class Filters implements HttpFilters { | |
| @Inject | |
| HostFilter hostFilter; | |
| @Override | |
| public EssentialFilter[] filters() { | |
| return new EssentialFilter[]{hostFilter}; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import play.api.mvc._ | |
| import play.api.{Logger, Routes} | |
| import play.api.libs.concurrent.Execution.Implicits.defaultContext | |
| import play.api.Play | |
| class HostFilter extends EssentialFilter { | |
| val host = Play.current.configuration.getString("swagger.api.host").getOrElse("") | |
| override def apply(nextFilter: EssentialAction) = new EssentialAction { | |
| def apply(requestHeader: RequestHeader) = { | |
| val newHeaders = requestHeader.headers.replace("Host" -> host) | |
| val newRequest = requestHeader.copy(headers = newHeaders) | |
| nextFilter(newRequest).map { result => | |
| result | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment