{"record":{"id":"e5c79502e994a0fc","repo":"nautechsystems/nautilus_trader","slug":"invalid-websocket-reconnect-header-value-e","errorCode":null,"errorMessage":"Invalid WebSocket reconnect header value: {e}","messagePattern":"Invalid WebSocket reconnect header value: (.+?)","errorType":"exception","errorClass":"TransportError","httpStatus":null,"severity":"error","filePath":"crates/network/src/websocket/client.rs","lineNumber":2282,"sourceCode":"        Self {\n            inner: Arc::new(RwLock::new(headers)),\n        }\n    }\n\n    /// Replaces a header used by future automatic reconnect attempts.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the header name or value is invalid.\n    pub fn update(&self, name: &str, value: &str) -> Result<(), TransportError> {\n        let name = HeaderName::from_bytes(name.as_bytes()).map_err(|e| {\n            TransportError::Io(std::io::Error::new(\n                std::io::ErrorKind::InvalidInput,\n                format!(\"Invalid WebSocket reconnect header name: {e}\"),\n            ))\n        })?;\n        HeaderValue::from_str(value).map_err(|e| {\n            TransportError::Io(std::io::Error::new(\n                std::io::ErrorKind::InvalidInput,\n                format!(\"Invalid WebSocket reconnect header value: {e}\"),\n            ))\n        })?;\n\n        let name = name.as_str();\n        let mut headers = self.inner.write();\n        headers.retain(|(existing, _)| !existing.eq_ignore_ascii_case(name));\n        headers.push((name.to_string(), value.to_string()));\n        Ok(())\n    }\n\n    fn snapshot(&self) -> Vec<(String, String)> {\n        self.inner.read().clone()\n    }\n}\n\nimpl Debug for ReconnectHeaders {","sourceCodeStart":2264,"sourceCodeEnd":2300,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/network/src/websocket/client.rs#L2264-L2300","documentation":"The reconnect header update API validates the value with HeaderValue::from_str. Header values must be visible ASCII (no control characters, no non-ASCII/UTF-8 multibyte content, no raw newlines). If the value fails validation, this InvalidInput TransportError is returned and the header is not stored. It is a caller input problem detected before any network I/O.","triggerScenarios":"Calling update(name, value) where value contains characters outside visible ASCII range, control characters, or embedded newlines — e.g. tokens read from files with trailing newline, or credentials with unicode characters.","commonSituations":"Reading API keys from files/env without trimming (embedded \\n or \\r); non-ASCII secrets or unicode quotes pasted into config; logging/formatted values containing control characters.","solutions":["Trim whitespace/newlines from the value before calling update (value.trim())","Ensure the value is pure visible ASCII; re-encode or fix the source of the credential if it contains other bytes","Validate the value in your config-loading layer before constructing the client"],"exampleFix":"// before\nlet key = std::fs::read_to_string(\"key.txt\")?; // may contain trailing \\n\nheaders.update(\"X-Api-Key\", &key)?;\n// after\nlet key = std::fs::read_to_string(\"key.txt\")?.trim().to_string();\nheaders.update(\"X-Api-Key\", &key)?;","handlingStrategy":"validation","validationCode":"fn is_valid_header_value(v: &str) -> bool {\n    !v.is_empty() && v.bytes().all(|b| (32..=126).contains(&b) || b == b'\\t')\n}\nlet value = raw_value.trim(); // strip file/env newlines","typeGuard":null,"tryCatchPattern":"match headers.update(name, &value) {\n    Err(e) if e.to_string().contains(\"header value\") => return Err(InvalidConfig(\"header value must be visible ASCII\".into())),\n    r => r?,\n}","preventionTips":["Always trim values read from files or environment variables","Ensure credentials/tokens are pure visible ASCII; re-encode sources containing other bytes","Reject embedded newlines at your config-validation layer"],"tags":["websocket","http-headers","validation","rust"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}