| 
									
										
										
										
											2022-05-31 20:35:23 -04:00
										 |  |  | package server | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  | import akka.http.scaladsl.settings.ParserSettings | 
					
						
							| 
									
										
										
										
											2022-05-31 20:35:23 -04:00
										 |  |  | import play.api.Logger | 
					
						
							|  |  |  | import play.core.server.AkkaHttpServer | 
					
						
							|  |  |  | import play.core.server.ServerProvider | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | import scala.concurrent.Future | 
					
						
							| 
									
										
										
										
											2022-05-31 20:35:23 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** Custom Akka HTTP server that allows us to overrides some Akka server settings as the current Play / Akka
 | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  |  *  versions we're using don't allow us to override these via conf files. Also handles base path redirects | 
					
						
							|  |  |  |  *  when play.http.context is configured. | 
					
						
							| 
									
										
										
										
											2022-05-31 20:35:23 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | class CustomAkkaHttpServer(context: AkkaHttpServer.Context) extends AkkaHttpServer(context) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  |   private lazy val logger = Logger(classOf[CustomAkkaHttpServer]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private lazy val basePath: String = { | 
					
						
							|  |  |  |     val contextPath = context.config.configuration.getOptional[String]("play.http.context").getOrElse("") | 
					
						
							|  |  |  |     val normalized = if (contextPath.trim.isEmpty) "" else contextPath.trim | 
					
						
							|  |  |  |     logger.info(s"Base path configured as: '$normalized'") | 
					
						
							|  |  |  |     normalized | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 20:35:23 -04:00
										 |  |  |   protected override def createParserSettings(): ParserSettings = { | 
					
						
							|  |  |  |     val defaultSettings: ParserSettings = super.createParserSettings() | 
					
						
							|  |  |  |     val maxHeaderCountKey = "play.http.server.akka.max-header-count" | 
					
						
							|  |  |  |     if (context.config.configuration.has(maxHeaderCountKey)) { | 
					
						
							|  |  |  |       val maxHeaderCount = context.config.configuration.get[Int](maxHeaderCountKey) | 
					
						
							|  |  |  |       logger.info(s"Setting max header count to: $maxHeaderCount") | 
					
						
							|  |  |  |       defaultSettings.withMaxHeaderCount(maxHeaderCount) | 
					
						
							|  |  |  |     } else | 
					
						
							|  |  |  |       defaultSettings | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 20:35:23 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** A factory that instantiates a CustomAkkaHttpServer. */ | 
					
						
							|  |  |  | class CustomAkkaHttpServerProvider extends ServerProvider { | 
					
						
							|  |  |  |   def createServer(context: ServerProvider.Context) = { | 
					
						
							|  |  |  |     val serverContext = AkkaHttpServer.Context.fromServerProviderContext(context) | 
					
						
							|  |  |  |     new CustomAkkaHttpServer(serverContext) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |