rust-websocket-lite
rust-websocket-lite copied to clipboard
RFC compliance for Upgrade request
Mentioned by @bluetech on ba1f935f250b8249f2581d0620784c0f45fc737a:
https://github.com/1tgr/rust-websocket-lite/blob/ba1f935f250b8249f2581d0620784c0f45fc737a/websocket-codec/src/upgrade.rs#L118
This function is not exactly right; it will also accept e.g.
Upgrade2
but it shouldn't.To be fully pedantic, the websocket RFC says:
- The request MUST contain an |Upgrade| header field whose value MUST include the "websocket" keyword.
- The request MUST contain a |Connection| header field whose value MUST include the "Upgrade" token.
The HTTP RFC describes the
Connection
andUpgrade
headers with the following syntax:Connection = 1#connection-option connection-option = token Upgrade = 1#protocol protocol = protocol-name ["/" protocol-version] protocol-name = token protocol-version = token token = 1*tchar tchar = (irrelevant) 1#element => element *( OWS "," OWS element ) OWS = *( SP / HTAB ) ; optional whitespace
Long story short:
for part in haystack.split(',') { let token = part.trim_start_matches([' ', '\t']).trim_end_matches([' ', '\t']); if token.eq_ignore_ascii_case(needle) { return true; } } return false;