Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
vic-ma committed Jun 14, 2024
1 parent a05e9ed commit 90b7916
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions course-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,15 @@ stages:
name: "Read header"
difficulty: very_easy
description_md: |-
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.
In this stage, you'll add support for `Accept-Encoding` headers that contain multiple compression schemes.
In this stage, you'll add support for the `Accept-Encoding` and `Content-Encoding` headers.
### Multiple compression schemes
### `Accept-Encoding` and `Content-Encoding`
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:
```
> GET /echo/foo HTTP/1.1
> Host: localhost:4221
> User-Agent: curl/7.81.0
> Accept: */*
> Accept-Encoding: gzip // Client specifies it supports the gzip compression scheme.
```
The server then chooses one of the compression schemes listed in `Accept-Encoding` and compresses the response body with it.
Then, the server sends a response with the compressed body and a `Content-Encoding` header. `Content-Encoding` specifies the compression scheme that was used.
In the following example, the response body is compressed with `gzip`:
A client can specify that it supports multiple compression schemes by setting `Accept-Encoding` to a comma-separated list:
```
< HTTP/1.1 200 OK
< Content-Encoding: gzip // Server specifies that the response body is compressed with gzip.
< Content-Type: text/plain // Original media type of the body.
< Content-Length: 23 // Size of the compressed body.
< ... // Compressed body.
Accept-Encoding: encoding-1, encoding-2, encoding-3
```
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.
For this extension, assume that your server only supports the `gzip` compression scheme.
For this stage, you don't need to compress the body. You'll implement compression in a later stage.
Expand All @@ -67,43 +46,38 @@ stages:
$ ./your_server.sh
```
The tester will then send two `GET` requests to the `/echo/<str>` endpoint on your server.
The tester will then send two `GET` requests to the `/echo/{str}` endpoint on your server.
#### First request
First, the tester will send a request with this header: `Accept-Encoding: gzip`.
For the first request, the `Accept-Encoding` header will contain `gzip`, along with some invalid encodings:
```
$ curl -v -H "Accept-Encoding: gzip" http://localhost:4221/echo/abc
$ curl -v -H "Accept-Encoding: invalid-encoding-1, gzip, invalid-encoding-2" http://localhost:4221/echo/abc
```
Your server's response must contain this header: `Content-Encoding: gzip`.
```
```javascript
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Encoding: gzip
... // Body omitted.
// Body omitted.
```
#### Second request
Next, the tester will send a request with this header: `Accept-Encoding: invalid-encoding`.
For the second request, the `Accept-Encoding` header will only contain invalid encodings:
```
$ curl -v -H "Accept-Encoding: invalid-encoding" http://localhost:4221/echo/abc
$ curl -v -H "Accept-Encoding: invalid-encoding-1, invalid-encoding-2" http://localhost:4221/echo/abc
```
Your server's response must not contain a `Content-Encoding` header:
```
```javascript
HTTP/1.1 200 OK
Content-Type: text/plain
... // Body omitted.
// Body omitted.
```
### Notes
- You'll add support for `Accept-Encoding` headers with multiple compression schemes in a later stage.
- There's another method for HTTP compression that uses the `TE` and `Transfer-Encoding` headers. We won't cover that method in this extension.
marketing_md: |-
In this stage, we'll do XYZ.
Expand Down

0 comments on commit 90b7916

Please sign in to comment.