Skip to content

Commit

Permalink
Add extra check to _response for "100 Continue" HTTP response
Browse files Browse the repository at this point in the history
This is a very simple check that only accounts for *one*
extra "100 Continue" HTTP response. It simpy reads once,
checks for status 100 and reads again, discarding everything
after the "Continue" response.
Not very clean, more of a proof of concept.
  • Loading branch information
fzs committed Jan 23, 2020
1 parent 687e13a commit efe5c10
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,22 @@ _response() {

_log debug "Response status is: ${status_code} ${status_text}"

if [ "${status_code}" = "100" ]; then
_log debug "Ignoring response '${status_code} ${status_text}', skipping to real response."
while IFS=": " read -r hdr val; do
# Headers stop at the first blank line.
[ "$hdr" = "$crlf" ] && break
val="${val%${crlf}}"
_log debug "Unexpected additional header: ${hdr}: ${val}"
done

read -r http_version status_code status_text
status_text="${status_text%${crlf}}"
http_version="${http_version#HTTP/}"

_log debug "Response status is: ${status_code} ${status_text}"
fi

headers="http_version: ${http_version}
status_code: ${status_code}
status_text: ${status_text}
Expand Down
20 changes: 20 additions & 0 deletions tests/unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,24 @@ Hi\n' | $SCRIPT _response Baz Bad Foo | {
}
}

test_response_headers_100_continue() {
# Test that process response 100 Continue is handled correctly.

local baz bar foo

printf 'HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200 OK\r\nServer: example.com\r\nFoo: Foo!\r\nBar: Bar!\r\nBaz: Baz!\r\n\r\nHi
' | $SCRIPT _response Baz Bad Foo | {
read -r baz
read -r bar # Ensure unfound items are blank.
read -r foo

ret=0
[ "$baz" = 'Baz!' ] || { ret=1; printf '`Baz!` != `%s`\n' "$baz"; }
[ "$bar" = '' ] || { ret=1; printf '`` != `%s`\n' "$bar"; }
[ "$foo" = 'Foo!' ] || { ret=1; printf '`Foo!` != `%s`\n' "$foo"; }

return $ret
}
}

_main "$@"

0 comments on commit efe5c10

Please sign in to comment.