简体   繁体   English

YARP - HttpRequestException:收到无效的状态行

[英]YARP - HttpRequestException: Received an invalid status line

I have a YARP gateway inside a docker compose.network.我在 docker compose.network 中有一个 YARP 网关。 On a development branch I see the following:在开发分支上,我看到以下内容:

info: Yarp.ReverseProxy.Forwarder.HttpForwarder[9]
      Proxying to http://<my-route> HTTP/2 RequestVersionOrLower no-streaming
info: Yarp.ReverseProxy.Forwarder.HttpForwarder[48]
      Request: An error was encountered before receiving a response.
      System.Net.Http.HttpRequestException: Received an invalid status line: '3b'.
         at System.Net.Http.HttpConnection.ParseStatusLine(ReadOnlySpan`1 line, HttpResponseMessage response)
         at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
         at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at Yarp.ReverseProxy.Forwarder.HttpForwarder.SendAsync(HttpContext context, String destinationPrefix, HttpMessageInvoker httpClient, ForwarderRequestConfig requestConfig, HttpTransformer transformer)

This happens for POST, PUT and DELETE methods but GET method works fine.这发生在 POST、PUT 和 DELETE 方法中,但 GET 方法工作正常。

The '3b' part changes. '3b'部分发生变化。 How can I find where this problem comes from?我怎样才能找到这个问题的根源?

A way to debug this issue would be to use a tool such as Fiddler or Charles to capture the HTTP requests and responses.调试此问题的一种方法是使用FiddlerCharles等工具来捕获 HTTP 请求和响应。 This will allow you to see the exact request that is failing and the response that is being returned, which will help you to identify where the issue is coming from.这将允许您查看失败的确切请求和返回的响应,这将帮助您确定问题的来源。

Alternatively , if you don't have access to such tools, you can also use a tool like Postman to make the request and inspect the response to help you narrow down the issue.或者,如果您无法访问此类工具,也可以使用Postman等工具来发出请求并检查响应,以帮助您缩小问题范围。

Looks like YARP is trying to parse a corrupted response as the status line is the first part of an HTTP response.看起来 YARP 正在尝试解析损坏的响应,因为状态行是 HTTP 响应的第一部分。 To be honest, this type of issue is tough to debug without seeing application level traffic as we could be dealing with a corrupted response from the POST request itself or a corruption that took place in the previous request.老实说,在没有看到应用程序级流量的情况下很难调试此类问题,因为我们可能正在处理来自 POST 请求本身的损坏响应或先前请求中发生的损坏。

Example: sending an actual body of 100 bytes, but setting the Content-Length to 98. A web client could be tricked into parsing the first 98 bytes of a response, leaving the last 2 bytes in the.network buffer and then corrupting the next request's response.示例:发送 100 字节的实际正文,但将 Content-Length 设置为 98。可以诱使 web 客户端解析响应的前 98 个字节,将最后 2 个字节留在 .network 缓冲区中,然后破坏下一个字节请求的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM