5

I have an IP camera that I'm trying to receive events from. For example, if it detects motion in a specific part of the frame, I want to know about it and get the images captured with the event.

The problem is that it uses HTTP/1.0 POST to send this information. According to the spec (https://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#BodyLength), the body length can either be communicated by the Content-Length header or by closing the connection when everything has been sent to the server. The IP camera does the latter of the two methods.

Kestrel's web server doesn't support this as seen here Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.For() contains the following (https://github.com/aspnet/KestrelHttpServer/blob/2191327b59f87f23f69fff2ac0dba9e58b67141b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs, Lines 308-318):

// Avoid slowing down most common case
if (!object.ReferenceEquals(context.Method, HttpMethods.Get))
{
    // If we got here, request contains no Content-Length or Transfer-Encoding header.
    // Reject with 411 Length Required.
    if (context.Method == HttpMethod.Post || context.Method == HttpMethod.Put)
    {
        var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10;
        BadHttpRequestException.Throw(requestRejectionReason, context.Method);
    }
}

As a result, Kestrel throws a BadHttpRequestException every time.

Any ideas on how to work around this issue?

  • TCP Server that can run next to Kestrel?

  • A low-level hook to add the content-length?

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Jaron
  • 133
  • 6
  • Maybe use a reverse proxy like Apache or Nginx? FWIW, if using Windows try [ContaCam](https://www.contaware.com/contacam.html) as an alternative. – Mark G Jul 06 '18 at 20:54
  • It looks like the Kestrel header parsing is very hard to override:https://github.com/aspnet/KestrelHttpServer/blob/2191327b59f87f23f69fff2ac0dba9e58b67141b/src/Kestrel.Core/KestrelServer.cs#L99-L108 – Shaun Luttin Jul 07 '18 at 08:06
  • How did you end up solving this? – Elia Grady Jul 04 '21 at 10:09

0 Answers0