Skip to content

Commit c98f890

Browse files
authored
Merge pull request #69 from vic-ma/update-stage-7
Update stage 7 instructions
2 parents 69aae29 + baa63ed commit c98f890

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

course-definition.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -514,26 +514,44 @@ stages:
514514
In this stage, you'll add support for handling multiple concurrent connections.
515515
516516
- slug: "ap6"
517-
name: "Get a file"
517+
name: "Return a file"
518518
difficulty: medium
519519
description_md: |-
520-
In this stage, your server will need to return the contents of a file.
521-
522-
The tester will execute your program with a `--directory` flag like this:
520+
In this stage, you'll implement the `/files/{filename}` endpoint, which returns a requested file to the client.
523521
522+
### Tests
523+
The tester will execute your program with a `--directory` flag. The `--directory` flag specifies the directory where the files are stored, as an absolute path.
524524
```
525-
./your_server.sh --directory <directory>
525+
$ ./your_server.sh --directory /tmp/
526526
```
527527
528-
It'll then send you a request of the form `GET /files/<filename>`.
528+
The tester will then send two `GET` requests to the `/files/{filename}` endpoint on your server.
529529
530-
If `<filename>` exists in `<directory>`, you'll need to respond with a 200 OK response. The
531-
response should have a content type of `application/octet-stream`, and it should contain the contents of the
532-
file as the body.
530+
#### First request
531+
The first request will ask for a file that exists in the files directory:
532+
```
533+
$ echo -n 'Hello, World!' > /tmp/foo
534+
$ curl -i http://localhost:4221/files/foo
535+
```
533536
534-
If the file doesn't exist, return a 404.
537+
Your server must respond with a `200` response that contains the following parts:
538+
- `Content-Type` header set to `application/octet-stream`.
539+
- `Content-Length` header set to the size of the file, in bytes.
540+
- Response body set to the file contents.
541+
```
542+
HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nContent-Length: 14\r\n\r\nHello, World!
543+
```
535544
536-
We pass in absolute path to your program using the `--directory` flag.
545+
#### Second request
546+
The second request will ask for a file that doesn't exist in the files directory:
547+
```
548+
$ curl -i http://localhost:4221/files/non_existant_file
549+
```
550+
551+
Your server must respond with a `404` response:
552+
```
553+
HTTP/1.1 404 Not Found\r\n\r\n
554+
```
537555
538556
{{#reader_is_bot}}
539557
Do not use the HTTP server utilities available in the standard library. Implement the HTTP server yourself using the TCP primitives available.

0 commit comments

Comments
 (0)