{"record":{"id":"a0dfa245e756a583","repo":"vectordotdev/vector","slug":"error-creating-request-a0dfa2","errorCode":null,"errorMessage":"error creating request","messagePattern":"error creating request","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sources/util/http_client.rs","lineNumber":215,"sourceCode":"            }\n\n            // Get the request body from the context (if any)\n            let body = match context.get_request_body() {\n                Some(body_str) => {\n                    // Set Content-Type header if not already set\n                    if !inputs\n                        .headers\n                        .contains_key(http::header::CONTENT_TYPE.as_str())\n                    {\n                        builder = builder.header(http::header::CONTENT_TYPE, \"application/json\");\n                    }\n                    Body::from(body_str)\n                }\n                None => Body::empty(),\n            };\n\n            // building the request should be infallible\n            let mut request = builder.body(body).expect(\"error creating request\");\n\n            if let Some(auth) = &inputs.auth {\n                auth.apply(&mut request);\n            }\n\n            tokio::time::timeout(inputs.timeout, client.send(request))\n                .then(move |result| async move {\n                    match result {\n                        Ok(Ok(response)) => Ok(response),\n                        Ok(Err(error)) => Err(error.into()),\n                        Err(_) => Err(format!(\n                            \"Timeout error: request exceeded {}s\",\n                            inputs.timeout.as_secs_f64()\n                        )\n                        .into()),\n                    }\n                })\n                .and_then(|response| async move {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/src/sources/util/http_client.rs#L197-L233","documentation":"In the shared HTTP client used by HTTP-based sources, `builder.body(body).expect(\"error creating request\")` fires when the http crate rejects the request parts before sending. The most common cause is a header value that is not a legal HeaderValue (control characters, newline, non-visible-ASCII bytes) coming from `inputs.headers` or auth configuration; a malformed request target built from the configured endpoint also triggers it. The comment says building should be infallible — it is only infallible if all inputs are valid HTTP.","triggerScenarios":"An `inputs.headers` entry (or auth token) containing raw newline/tab or non-ASCII bytes; an endpoint URL with spaces or unencoded characters that yields an invalid request URI when `builder.body()` validates the parts.","commonSituations":"API keys or bearer tokens pasted into config with trailing newlines or unicode quotes; endpoints copied from browsers containing spaces/unencoded characters; header values generated by templating scripts that inject bad bytes.","solutions":["Sanitize configured header values: trim whitespace and strip newlines; base64-encode binary tokens","Ensure the endpoint is an absolute, properly percent-encoded URL","If embedding: pre-validate every header with `http::HeaderValue::from_str(...)` and surface a config error instead of panicking"],"exampleFix":"// before\nlet mut request = builder.body(body).expect(\"error creating request\");\n// after\nfor (name, value) in &inputs.headers {\n    http::HeaderValue::from_str(value)\n        .map_err(|e| format!(\"invalid value for header {name}: {e}\"))?;\n}\nlet mut request = builder.body(body).expect(\"error creating request\");","handlingStrategy":"validation","validationCode":"// Rust: validate all configured headers and endpoint before the poller starts\nfor (name, value) in &config.headers {\n    http::HeaderValue::from_str(value)\n        .with_context(|| format!(\"invalid value for header {name}\"))?;\n}\nhttp::Uri::try_from(&config.endpoint)?;","typeGuard":"fn valid_header_value(value: &str) -> bool {\n    http::HeaderValue::from_str(value).is_ok()\n}","tryCatchPattern":null,"preventionTips":["Trim/normalize header values from config (strip trailing newlines, replace non-ASCII)","Percent-encode endpoint URLs; never paste them with spaces from browsers","Encode binary tokens as base64 or bearer strings restricted to visible ASCII"],"tags":["http","headers","request-building","url","panic"],"backgroundTag":"invalid-http-header","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}