Skip to content

Commit c090b2f

Browse files
committed
Update compression 1 instructions
1 parent 69c46cb commit c090b2f

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

course-definition.yml

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -638,68 +638,89 @@ stages:
638638

639639
- slug: "df4"
640640
primary_extension_slug: "http-compression"
641-
name: "Content-Encoding header"
641+
name: "Compression headers"
642642
difficulty: easy
643643
description_md: |
644-
Welcome to the HTTP Compression Extension! In this extension, you'll add [Compression](https://en.wikipedia.org/wiki/HTTP_compression) support to your HTTP Server implementation.
644+
Welcome to the HTTP Compression extension! In this extension, you'll add support for [compression](https://en.wikipedia.org/wiki/HTTP_compression) to your HTTP server.
645645
646-
In this stage, you'll add support for the Content-Encoding header based on what the client sends.
646+
In this stage, you'll add support for the `Accept-Encoding` and `Content-Encoding` headers.
647647
648-
### Tests
648+
### `Accept-Encoding` and `Content-Encoding`
649649
650-
The tester will execute your program like this:
650+
An HTTP client uses the `Accept-Encoding` header to specify the compression schemes it supports. In the following example, the client specifies that it supports the `gzip` compression scheme:
651+
```
652+
> GET /echo/foo HTTP/1.1
653+
> Host: localhost:4221
654+
> User-Agent: curl/7.81.0
655+
> Accept: */*
656+
> Accept-Encoding: gzip // Client specifies it supports the gzip compression scheme.
657+
```
651658
652-
```bash
653-
./your_server.sh
659+
The server then chooses one of the compression schemes listed in `Accept-Encoding` and compresses the response body with it.
660+
661+
Then, the server sends a response with the compressed body and a `Content-Encoding` header. `Content-Encoding` specifies the compression scheme that was used.
662+
663+
In the following example, the response body is compressed with `gzip`:
664+
```
665+
< HTTP/1.1 200 OK
666+
< Content-Encoding: gzip // Server specifies that the response body is compressed with gzip.
667+
< Content-Type: text/plain // Original media type of the body.
668+
< Content-Length: 23 // Size of the compressed body.
669+
< ... // Compressed body.
654670
```
655671
656-
It'll then send an HTTP `GET` request to the `/echo/<a-random-string>` endpoint. In the request, it'll include an Accept-Encoding header like: `Accept-Encoding: gzip`.
657-
As an example, here's a request you might receive:
672+
If the server doesn't support any of the compression schemes specified by the client, then it will not compress the response body. Instead, it will send a standard response and omit the `Content-Encoding` header.
658673
674+
For this extension, assume that your server only supports the `gzip` compression scheme.
675+
676+
For this stage, you don't need to compress the body. You'll implement compression in a later stage.
677+
678+
### Tests
679+
680+
The tester will execute your program like this:
659681
```
660-
GET /echo/foo HTTP/1.1
661-
Host: localhost:4221
662-
User-Agent: curl/7.64.1
663-
Accept-Encoding: gzip
682+
$ ./your_server.sh
664683
```
665684
666-
Your server must respond with a `200 OK` response. The response should have a `Content-Encoding: gzip` header present. The response body will not be tested in this stage. (We will tackle the actual compression in a later stage)
667-
Here's the response you're expected to send back:
685+
The tester will then send two `GET` requests to the `/echo/<str>` endpoint on your server.
686+
687+
#### First request
688+
689+
First, the tester will send a request with this header: `Accept-Encoding: gzip`.
690+
```
691+
$ curl -v -H "Accept-Encoding: gzip" http://localhost:4221/echo/abc
692+
```
668693
694+
Your server's response must contain this header: `Content-Encoding: gzip`.
669695
```
670696
HTTP/1.1 200 OK
671-
Content-Encoding: gzip
672697
Content-Type: text/plain
698+
Content-Encoding: gzip
673699
Content-Length: 3
674700
675-
foo
701+
abc
676702
```
677703
678-
It'll then send another HTTP `GET` request to the `/echo/<a-random-string>` endpoint. In the request, it'll include an Accept-Encoding header like: `Accept-Encoding: invalid-encoding`.
679-
But this time the Accept-Encoding header will be set to an invalid value (i.e. an encoding that your server doesn't support).
680-
As an example, here's a request you might receive:
704+
#### Second request
681705
706+
Next, the tester will send a request with this header: `Accept-Encoding: invalid-encoding`.
682707
```
683-
GET /echo/bar HTTP/1.1
684-
Host: localhost:4221
685-
User-Agent: curl/7.64.1
686-
Accept-Encoding: invalid-encoding
708+
$ curl -v -H "Accept-Encoding: invalid-encoding" http://localhost:4221/echo/abc
687709
```
688710
689-
Your server must respond with a `200 OK` response. The response should NOT have a `Content-Encoding` header present. The response body will not be tested in this stage.
690-
Here's the response you're expected to send back:
691-
711+
Your server's response must not contain a `Content-Encoding` header:
692712
```
693713
HTTP/1.1 200 OK
694714
Content-Type: text/plain
695715
Content-Length: 3
696716
697-
bar
717+
abc
698718
```
699719
700720
### Notes
701721
702-
1. Header names are case-insensitive, i.e. `accept-encoding: gzip` and `Accept-Encoding: gzip` are equivalent. We won't test this explicitly in this challenge, but it's a good practice to lowercase your header names before comparison.
722+
- You'll add support for `Accept-Encoding` headers with multiple compression schemes in a later stage.
723+
- There's another method for HTTP compression that uses the `TE` and `Transfer-Encoding` headers. We won't cover that method in this extension.
703724
marketing_md: |
704725
In this stage, you'll add support for reading the `Accept-Encoding` header sent by clients, and respond with `Content-Encoding` header in your response.
705726

0 commit comments

Comments
 (0)