Skip to content

support POST #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bashttpd
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,35 @@ read -r REQUEST_METHOD REQUEST_URI REQUEST_HTTP_VERSION <<<"$line"
|| fail_with 400

# Only GET is supported at this time
[ "$REQUEST_METHOD" = "GET" ] || fail_with 405
[ "$REQUEST_METHOD" = "GET" ] || [ "$REQUEST_METHOD" = "POST" ] || fail_with 405

declare -a REQUEST_HEADERS
declare -a POST_VALUES

length=0
while read -r line; do
line=${line%%$'\r'}
recv "$line"

# If we've reached the end of the headers, break.
[ -z "$line" ] && break

if [[ "$line" =~ Content-Length ]]; then
length=$(echo $line | cut -d':' -f2)
fi

REQUEST_HEADERS+=("$line")
done

if [[ "$REQUEST_METHOD" = "POST" ]]; then

read -n $length -r contents

_IFS=$IFS
IFS=\&
POST_VALUES=($contents)
IFS=$_IFS
fi

source bashttpd.conf
fail_with 500