Skip to content

Commit

Permalink
vibe-d#1490 Add support for X-Forwarded-Port header.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail-K authored and Mihail-K committed May 12, 2016
1 parent 370915b commit c73a323
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions source/vibe/http/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -707,28 +707,51 @@ final class HTTPServerRequest : HTTPRequest {
@property URL fullURL()
const {
URL url;
auto fh = this.headers.get("X-Forwarded-Host", "");
if (!fh.empty) {
url.schema = this.headers.get("X-Forwarded-Proto", "http");
url.host = fh;

// Set URL host segment.
if (auto xfh = this.headers.get("X-Forwarded-Host")) {
url.host = xfh;
} else if (!this.host.empty) {
url.host = this.host;
} else if (!m_settings.hostName.empty) {
url.host = m_settings.hostName;
} else {
if (!this.host.empty) url.host = this.host;
else if (!m_settings.hostName.empty) url.host = m_settings.hostName;
else url.host = m_settings.bindAddresses[0];
url.host = m_settings.bindAddresses[0];
}

// Set URL schema segment.
if (auto xfp = this.headers.get("X-Forwarded-Proto")) {
url.schema = xfp;
} else if (this.tls) {
url.schema = "https";
} else {
url.schema = "http";
}

if (this.tls) {
url.schema = "https";
if (m_port != 443) url.port = m_port;
// Set URL port segment.
Nullable!ushort port;
if (auto xfp = this.headers.get("X-Forwarded-Port")) {
try {
port = xfp.to!ushort;
} catch (ConvException) {
// Value was not ushort.
}
}
if (port.isNull) {
if (url.schema == "https") {
url.port = 443U;
} else {
url.schema = "http";
if (m_port != 80) url.port = m_port;
url.port = 80U;
}
}

url.host = url.host.split(":")[0];
url.port = port.get;
url.username = this.username;
url.password = this.password;
url.path = Path(path);
url.queryString = queryString;

return url;
}

Expand Down

0 comments on commit c73a323

Please sign in to comment.