benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf fc110b64-ae49-5911-9d57-aeab5a912da5

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import re
import os


def task_func(request):
    """
    Handles an HTTP GET request to retrieve a static file from the server.

    This function processes an HTTP GET request, extracts the filename from it, checks the existence of the file
    in the server's directory, and returns an HTTP response. The response either contains the file content (if found) or an
    appropriate error message (if not found or if the request is invalid).

    Parameters:
    - request (str): An HTTP GET request in string format. The expected format is "GET /<filename> HTTP/1.1".

    Returns:
    - str: An HTTP response string, which includes the status code, content length (for 200 OK responses), and the file content
           or an error message.

    Requirements:
    - os
    - re

    Examples:
    >>> task_func("GET /test.txt HTTP/1.1")
    "HTTP/1.1 200 OK\r\nContent-Length: <size of test.txt>\r\n\r\n<contents of test.txt>"
    >>> task_func("GET /nonexistent.txt HTTP/1.1")
    "HTTP/1.1 404 NOT FOUND\r\n\r\nFile Not Found"
    >>> task_func("INVALID REQUEST")
    "HTTP/1.1 400 BAD REQUEST\r\n\r\nBad Request"
    >>> task_func("GET /restricted.txt HTTP/1.1") # Assuming an I/O error occurs
    "HTTP/1.1 500 INTERNAL SERVER ERROR\r\n\r\nInternal Server Error"
    """

instruct prompt

Handles an HTTP GET request to retrieve a static file from the server. This function processes an HTTP GET request, extracts the filename from it, checks the existence of the file in the server's directory, and returns an HTTP response. The response either contains the file content (if found) or an appropriate error message (if not found or if the request is invalid).
The function should output with:
    str: An HTTP response string, which includes the status code, content length (for 200 OK responses), and the file content
    or an error message.
You should write self-contained code starting with:

Code

import re
import os
def task_func(request):

code prompt

Code

import re
import os
def task_func(request):

entry point

task_func

libs

  • re
  • os

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import