Skip to content

Commit

Permalink
Fix #606 Set serverName to localhost if HOST header does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocdaothanh committed Jun 10, 2016
1 parent bd5a5f8 commit 802cbfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/xitrum/action/Net.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ trait Net {

lazy val (serverName, serverPort) = {
val np = request.headers.get(HttpHeaderNames.HOST) // Ex: localhost, localhost:3000
val xs = np.split(':')
if (xs.length == 1) {
if (np == null) {
val port = if (isSsl) 443 else 80
(xs(0), port)
("localhost", port)
} else {
(xs(0), xs(1).toInt)
val xs = np.split(':')
if (xs.length == 1) {
val port = if (isSsl) 443 else 80
(xs(0), port)
} else {
(xs(0), xs(1).toInt)
}
}
}
}
3 changes: 1 addition & 2 deletions src/main/scala/xitrum/handler/outbound/SetCORS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ class SetCORS extends ChannelOutboundHandlerAdapter {
val request = env.request
val response = env.response

val requestOrigin = request.headers.get(ORIGIN)

// Access-Control-Allow-Origin
if (!response.headers.contains(ACCESS_CONTROL_ALLOW_ORIGIN)) {
val requestOrigin = request.headers.get(ORIGIN)
if (corsAllowOrigins.head.equals("*")) {
if (requestOrigin == null || requestOrigin == "null")
response.headers.set(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
Expand Down

0 comments on commit 802cbfb

Please sign in to comment.