Permalink
Browse files

Fixed bug in 0.10 release causing content-type not to be properly set

Added feature to automatically set content-length if not already set and available
Added ServerConfig.name to allow setting the header for Server
Added `Server` header support
  • Loading branch information...
darkfrog26 committed Feb 2, 2019
1 parent 40efc23 commit 55bdb2ea5e996ff0f956169c43fe1ffbcc4163eb
@@ -62,6 +62,7 @@ object Headers {
Header(this, value)
}
}
case object `Server` extends StringHeaderKey("Server")
def `Set-Cookie` = SetCookie
case object `Content-Disposition` extends HeaderKey {
override def key: String = "Content-Disposition"
@@ -8,6 +8,11 @@ import profig.Profig
import reactify._

class ServerConfig(server: Server) {
/**
* The Server name set in the HTTP header
*/
val name: Var[String] = Var(Profig("server.name").as[String]("youi"))

object session {
private val config = Profig("session").as[SessionConfig]

@@ -258,15 +258,28 @@ object UndertowServerImplementation extends ServerImplementationCreator {
}

private def handleStandard(impl: UndertowServerImplementation, connection: HttpConnection, exchange: HttpServerExchange): Unit = {
connection.response.content.foreach { content =>
if (Headers.`Content-Type`.value(connection.response.headers).isEmpty) {
connection.modify { response =>
response.withHeader(Headers.`Content-Type`(content.contentType))
}
val response = {
var response = connection.response

// Add the Server header if not already set
if (Headers.Response.`Server`.value(response.headers).isEmpty) {
response = response.withHeader(Headers.Response.`Server`(impl.server.config.name()))
}
}

val response = connection.response
connection.response.content.map { content =>
// Add Content-Type from Content if not already set on the response
if (Headers.`Content-Type`.value(response.headers).isEmpty) {
response = response.withHeader(Headers.`Content-Type`(content.contentType))
}

// Set the Content-Length from Content if not already set on the response
if (Headers.`Content-Length`.value(response.headers).isEmpty && content.length != -1L) {
response = response.withHeader(Headers.`Content-Length`(content.length))
}

response
}.getOrElse(connection.response)
}

exchange.setStatusCode(response.status.code)
response.headers.map.foreach {

0 comments on commit 55bdb2e

Please sign in to comment.