{"record":{"id":"06f41e564de95beb","repo":"affaan-m/ECC","slug":"missing-http-method","errorCode":null,"errorMessage":"Missing HTTP method","messagePattern":"Missing HTTP method","errorType":"http","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/main.rs","lineNumber":4219,"sourceCode":"        if let Some(index) = buffer.windows(4).position(|window| window == b\"\\r\\n\\r\\n\") {\n            break index + 4;\n        }\n        if buffer.len() > 64 * 1024 {\n            anyhow::bail!(\"HTTP request headers too large\");\n        }\n    };\n\n    let header_text = String::from_utf8(buffer[..header_end].to_vec())\n        .context(\"HTTP request headers were not valid UTF-8\")?;\n    let mut lines = header_text.split(\"\\r\\n\");\n    let request_line = lines\n        .next()\n        .filter(|line| !line.trim().is_empty())\n        .ok_or_else(|| anyhow::anyhow!(\"Missing HTTP request line\"))?;\n    let mut request_parts = request_line.split_whitespace();\n    let method = request_parts\n        .next()\n        .ok_or_else(|| anyhow::anyhow!(\"Missing HTTP method\"))?\n        .to_string();\n    let path = request_parts\n        .next()\n        .ok_or_else(|| anyhow::anyhow!(\"Missing HTTP path\"))?\n        .to_string();\n\n    let mut headers = BTreeMap::new();\n    for line in lines {\n        if line.is_empty() {\n            break;\n        }\n        if let Some((key, value)) = line.split_once(':') {\n            headers.insert(key.trim().to_ascii_lowercase(), value.trim().to_string());\n        }\n    }\n\n    let content_length = headers\n        .get(\"content-length\")","sourceCodeStart":4201,"sourceCodeEnd":4237,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/main.rs#L4201-L4237","documentation":"Thrown by read_http_request when the request line is present and non-empty (it passed the blank-line filter) but split_whitespace yields no first token to use as the HTTP method. The parser needs METHOD PATH VERSION and bails if the method token is absent.","triggerScenarios":"Effectively a defensive guard: because the prior filter rejects lines that trim to empty, split_whitespace would normally yield at least one token. It can still fire if the request line is composed solely of whitespace-like characters that pass the empty check in some edge form, or if a future refactor weakens the filter. Nominal trigger is a first line with no recognizable method token.","commonSituations":"Malformed hand-crafted requests, buggy custom HTTP clients that emit a request line with only delimiters, or protocol probes that send non-HTTP bytes whose first line happens to be non-empty but contains no method.","solutions":["Inspect the raw bytes the client sent (tcpdump/Wireshark or log the buffer) and fix the client to send a well-formed request line like 'GET / HTTP/1.1'.","Treat this as a 400 Bad Request at the accept site instead of crashing the listener.","If you control the client, validate the request line before writing it to the socket."],"exampleFix":"// caller: classify parse failures as client errors\nmatch read_http_request(&mut stream) {\n    Ok(req) => dispatch(req),\n    Err(e) if e.to_string().contains(\"Missing HTTP method\") => {\n        let _ = write_http_response(&mut stream, 400, \"text/plain\", \"bad request line\");\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"fn has_method_token(request_line: &str) -> bool {\n    request_line.trim().split_whitespace().next().is_some()\n}","typeGuard":null,"tryCatchPattern":"match read_http_request(&mut stream) {\n    Ok(req) => dispatch(req),\n    Err(e) if e.to_string().contains(\"Missing HTTP method\") => {\n        let _ = write_http_response(&mut stream, 400, \"text/plain\", \"bad request line\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat any header-parse failure as a client-side 400, not a server crash.","Unit-test the parser against common malformed inputs."],"tags":["http","network","input-validation","tcp-server"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}