balena-labs-projects / balena-cam

Network Camera with Raspberry Pi and WebRTC. Tutorial:
https://balena.io/blog/build-a-raspberry-pi-based-network-camera/
MIT License
175 stars 78 forks source link

Conform to RFC 1341 Content-Type multipart boundary specification #51

Closed stenbergd closed 4 years ago

stenbergd commented 4 years ago

I've been toying around with this project on my RPi2 as a way of exploring the Balena concepts and got curious about the Content-Type 'multipart/x-mixed-replace' where a boundary is specified for each stream frame.

According to RFC 1341, section 7.2 The Multipart Content-Type, subsection 7.2.1 Multipart: The common syntax (Link: https://tools.ietf.org/html/rfc1341):

The encapsulation boundary is defined as a line consisting entirely of two hyphen characters ("-", decimal code 45) followed by the boundary parameter value from the Content-Type header field.

...

Thus, a typical multipart Content-Type header field might look like this:

Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p

This indicates that the entity consists of several parts, each itself with a structure that is syntactically identical to an RFC 822 message, except that the header area might be completely empty, and that the parts are each preceded by the line

--gc0p4Jq0M2Yt08jU534c0p

Thus, the server.py code:

response = web.StreamResponse(status=200, reason='OK', headers={
        'Content-Type': 'multipart/x-mixed-replace; '
                        'boundary=--%s' % boundary,
    })

Should be changed to:

response = web.StreamResponse(status=200, reason='OK', headers={
        'Content-Type': 'multipart/x-mixed-replace; '
                        'boundary=%s' % boundary,
    })

Doesn't seem to be a big deal though, it seems to work pretty well regardless :)

Thank you for a bunch of great examples on how to use Balena!

Best regards Daniel

stenbergd commented 4 years ago

I've created a pull request for this: https://github.com/balena-io-projects/balena-cam/pull/52

stenbergd commented 4 years ago

Aforementioned PR merged.