When implementing HTTP/TCP/WebSocket/networking logic, treat protocol semantics as “correctness-critical”: don’t rely on accidental behavior, and don’t assume inputs are single-valued.
Apply these rules: 1) Be consistent about connection lifecycle
2) Defensively handle multi-value headers
3) Normalize outbound URLs
4) Avoid fragile query parsing/merging
5) Parse WebSocket subprotocol lists correctly
Sec-WebSocket-Protocol, treat it as a list of tokens and compare exact compatible values—don’t use substring matching.Example (multi-value header handling):
local function first_header_value(v)
if type(v) == "table" then
return v[1]
end
return v
end
local instana_t = first_header_value(headers["x-instana-t"])
local instana_s = first_header_value(headers["x-instana-s"])
Enter the URL of a public GitHub repository