fn read_reason_phrase(buf: &mut impl Buf) -> Result<Vec<u8>, CodecError>Expand description
Read a Reason Phrase, holding it to the cap the draft states for the reader.
Section 1.4.3: “The reason phrase length has a maximum length of 1024 bytes. If an endpoint receives a length exceeding the maximum, it MUST close the session with a PROTOCOL_VIOLATION”.
The rule is written for the receiver, and the receiver is the side that was missing it: every encoder here already refused an over-long phrase, so the codec held itself to a rule it applied to nobody else. A control message may be 65,535 bytes, so a peer could hand the application a reason phrase sixty-four times the permitted length, on any of the nine messages that carry one.
The length is checked before the bytes are read, so an over-long phrase costs nothing to refuse.