IISExpress 10 不会 return 通过 HTTPS 的原因短语

IISExpress 10 will not return reasonphrase over HTTPS

在 IISExpress 10 和 VS2015 网络中使用 HTTPS 时 api 控制器不会发回 HttpResponseMessage 的 ReasonPhrase。如果我通过 HTTP 连接它工作正常,但 HTTPS 只是清除了原因短语。当部署到 Azure 时,这不会发生(https 按预期工作),它只发生在我的本地机器上。

您可以通过制作一个新的 mvc 应用程序来重现这一点,该应用程序具有 Web api 支持,框架 4.5.2。创建一个新的 web api 控制器(它将对 mvc 控制器和 HttpStatusCodeResult 执行相同的操作)并添加一个 post 命令,例如:

public HttpResponseMessage Post()
{
    var ret = new HttpResponseMessage((HttpStatusCode)270) { ReasonPhrase = "Test reason phrase", Content = new StringContent("test content") };
    return ret;
}

我用 postman 来测试它。在 http 上,状态将为

270 Test reason phrase

通过 HTTPS 它将只是

270 OK

您可以设置断点并查看 ret 设置是否正确,无论请求来自何处,因此 IIS 中的某些内容正在覆盖 HTTPS 上的 ReasonPhrase。

我已经尝试将 web.config 中的 httpErrors 设置为 errorMode 和 existingResponse 的几乎所有组合。我的 machine.config(适用于任何版本的 .net)未设置为在任何地方零售。 .vs 中的 application.config 将 httpErrors 设置为 overrideModeDefault="Allow".

我想不出也找不到任何其他修改设置的建议。这只是 iisexpress 的 bug/limitation 吗?还是我缺少一些神奇的设置?

更新:

我用 windows 10 和 VS2015 制作了一个 VM 来测试。相同的结果。我还在 VM 上启用了 IIS(普通 IIS)并发布到它。同样的结果。

为了好玩,我还将状态代码更改为 570,结果相同,“570 OK”,我觉得这很有趣,因为 5xx 不被视为成功代码,所以我期望的结果与 OK 不同。

我 运行 遇到了同样的问题,看起来这是由于 IIS 10.0 使用 HTTP/2 以及您的浏览器,它不允许使用 ReasonPhrase 字段。

https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2.4

8.1.2.4. Response Pseudo-Header Fields

For HTTP/2 responses, a single ":status" pseudo-header field is defined that carries the HTTP status code field (see [RFC7231], Section 6). This pseudo-header field MUST be included in all responses; otherwise, the response is malformed (Section 8.1.2.6).

HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.