To handle methods other than GET, you can modify the handle_request function to include conditional statements for other HTTP methods like POST, PUT, DELETE, etc. Here's an updated version of the script:
#!/bin/sh

# Set the listening port
PORT=8080

# Define the HTTP response headers
HTTP_OK="HTTP/1.1 200 OK"
HTTP_METHOD_NOT_ALLOWED="HTTP/1.1 405 Method Not Allowed"
CONTENT_TYPE_HTML="Content-Type: text/html"
CONNECTION_CLOSE="Connection: close"

# Define the HTML response body
HELLO_WORLD_RESPONSE="<!DOCTYPE html>
<html>
<head>
    <title>Hello, World!</title>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>"

# Define the function to handle incoming HTTP requests
handle_request() {
    request_method=$(echo "$1" | grep -oP '^\w+')

    if [ "$request_method" = "GET" ]; then
        response="$HTTP_OK\n$CONTENT_TYPE_HTML\n$CONNECTION_CLOSE\n\n$HELLO_WORLD_RESPONSE"
    elif [ "$request_method" = "POST" ]; then
        # Handle POST request
        response="$HTTP_OK\n$CONTENT_TYPE_HTML\n$CONNECTION_CLOSE\n\n<p>Received a POST request</p>"
    elif [ "$request_method" = "PUT" ]; then
        # Handle PUT request
        response="$HTTP_OK\n$CONTENT_TYPE_HTML\n$CONNECTION_CLOSE\n\n<p>Received a PUT request</p>"
    elif [ "$request_method" = "DELETE" ]; then
        # Handle DELETE request
        response="$HTTP_OK\n$CONTENT_TYPE_HTML\n$CONNECTION_CLOSE\n\n<p>Received a DELETE request</p>"
    else
        response="$HTTP_METHOD_NOT_ALLOWED\n$CONNECTION_CLOSE\n\nMethod Not Allowed"
    fi

    echo -e "$response"
}

# Continuously listen for HTTP requests using netcat (nc)
while true; do
    request=$(echo -e "HTTP/1.1 200 OK\n\n" | nc -l -p "$PORT" -q 1)
    response=$(handle_request "$request")
    echo "$response" | nc -l -p "$PORT" -q 1
done
This script now includes conditional statements to handle POST, PUT, and DELETE requests, in addition to the original handling of GET requests. The response for each method includes a different message to indicate that the request was received.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence