I’ve finished the challenge but when refactoring I run into this issue: Content-Encoding header should not be present on http-server challenge #IJ8 Multiple compression schemes. The the test claims that I am including Content-Encoding in the response when the Accept-Encoding are all invalid. But this isn’t true when I run the exact same curl command.
I’ve tried logging on my own beside the codecrafters debug to see if I am actually including the header, nothing gets printed: I am not including the header.
Below you’ll find the test logs:
remote: [tester::#IJ8] $ curl -v http://localhost:4221/echo/apple -H "Accept-Encoding: encoding-1, encoding-2"
remote: [tester::#IJ8] > GET /echo/apple HTTP/1.1
remote: [tester::#IJ8] > Host: localhost:4221
remote: [tester::#IJ8] > Accept-Encoding: encoding-1, encoding-2
remote: [tester::#IJ8] >
remote: [tester::#IJ8] Sent bytes: "GET /echo/apple HTTP/1.1\r\nHost: localhost:4221\r\nAccept-Encoding: encoding-1, encoding-2\r\n\r\n"
remote: [tester::#IJ8] Received bytes: "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 5\r\nContent-Encoding: gzip\r\n\r\napple"
remote: [tester::#IJ8] < HTTP/1.1 200 OK
remote: [tester::#IJ8] < Content-Type: text/plain
remote: [tester::#IJ8] < Content-Length: 5
remote: [tester::#IJ8] < Content-Encoding: gzip
remote: [tester::#IJ8] <
remote: [tester::#IJ8] < apple
remote: [tester::#IJ8] <
remote: [tester::#IJ8] Received response with 200 status code
remote: [tester::#IJ8] Content-Encoding header should not be present
remote: [tester::#IJ8] Test failed
remote: [tester::#IJ8] Terminating program
remote: [tester::#IJ8] Program terminated successfully
Here you will find the the response when I run the exact same command locally, no header is included.
$ curl -v http://localhost:4221/echo/grape -H "Accept-Encoding: encoding-1, encoding-2"
* Trying 127.0.0.1:4221...
* Connected to localhost (127.0.0.1) port 4221 (#0)
> GET /echo/grape HTTP/1.1
> Host: localhost:4221
> User-Agent: curl/7.84.0
> Accept: */*
> Accept-Encoding: encoding-1, encoding-2
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Content-Length: 5
<
grape* Connection #0 to host localhost left intact
And here’s a snippet of my code:
elif path[0] == "echo":
echo_string = path[-1]
client_compression = request.header.accept_encoding or ""
if "gzip" in client_compression:
echo_string = gzip.compress(echo_string.encode())
response.headers.content_encoding = "gzip"
response.headers.content_type = "text/plain"
response.headers.content_length = len(echo_string)
response.body = echo_string
Thanks in advance!