http-headers parser fails on whitespace-only lines
Author: tunglambkCreated Sep 14, 2026Updated Sep 15, 2026
Labelsbugready-to-ship
Describe the bug
http_headers skips empty lines but not whitespace-only ones. filter(None, data.splitlines()) keeps a line containing only spaces or tabs, and the parser then reads its first word:
first_word = line.split(maxsplit=1)[0]which raises IndexError for that line. On the command line this becomes "http-headers parser could not parse the input data". curl_head has the same failure because it calls http_headers.parse.
To Reproduce
printf 'GET / HTTP/1.1\nHost: example.com\n \nAccept: */*\n' | jc --http-headersjc: Error - http-headers parser could not parse the input data. ...import jc.parsers.http_headers as http_headers
http_headers.parse('GET / HTTP/1.1\nHost: example.com\n \nAccept: */*\n', quiet=True)
# IndexError: list index out of rangeA response with a whitespace-only line fails the same way, and so does jc --curl-head for the same input.
Expected behavior
Whitespace-only lines are treated like the empty lines the parser already drops, so the surrounding request or response still parses. hosts got the same treatment in #742/#743.
Environment
- jc version: 1.26.0 (
dev) - Python version: 3.13
Source: kellyjonbrazil/jc