0

在请求处理程序中,处理例如GET https://example.com/collections/1或 POSThttp://0.0.0.0:8080/collections我如何分别获取服务器地址https://example.comhttp://0.0.0.0:8080

目前我正在像这样构建它

 var url = "\(httpPrefix)\(server.serverAddress)"
 if server.serverPort != 443 { url += ":\(server.serverPort)" }

哪里httpPrefix是:

let httpPrefix = isLinux ? "https://" : "http://"

但感觉有更好的方法...

4

1 回答 1

0

我发现host标头将包含example.com0.0.0.0:8080取决于服务器。

因此,以下仅产生我需要的结果。httpScheme仍然是硬编码的(这是我不喜欢的,但还没有看到其他选项)。

httpScheme + request.header(.host)!

我正在强制展开,因为我观察到主机头总是在那里。

于 2017-03-24T12:44:48.757 回答