Skip to content

Commit d8f8d1a

Browse files
committed
Update stage 8 instructions
1 parent 9e905d9 commit d8f8d1a

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

course-definition.yml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,23 +560,57 @@ stages:
560560
In this stage, you'll add support for serving the contents of a file.
561561
562562
- slug: "qv8"
563-
name: "Post a file"
563+
name: "Read request body"
564564
difficulty: medium
565565
description_md: |-
566-
In this stage, your server will need to accept the contents of a file in a POST request and save it to a directory.
566+
In this stage, you'll add support for the `POST` method of the `/files/{filename}` endpoint, which accepts text from the client and creates a new file with that text.
567567
568-
Just like in the previous stage, the tester will execute your program with a `--directory` flag like this:
568+
### Request body
569569
570+
A request body is used to send data from the client to the server.
571+
572+
Here's an example of a `POST /files/{filename}` request:
573+
```
574+
// Request line
575+
POST /files/number HTTP/1.1
576+
\r\n
577+
578+
// Headers
579+
Host: localhost:4221\r\n
580+
User-Agent: curl/7.64.1\r\n
581+
Accept: */*\r\n
582+
Content-Type: application/octet-stream // Header that specifies the format of the request body
583+
Content-Length: 5\r\n // Header that specifies the size of the request body, in bytes
584+
\r\n
585+
586+
// Request Body
587+
12345
570588
```
571-
./your_server.sh --directory <directory>
589+
590+
### Tests
591+
592+
The tester will execute your program with a `--directory` flag. The `--directory` flag specifies the directory to create the file in, as an absolute path.
593+
```
594+
$ ./your_server.sh --directory /tmp/
572595
```
573596
574-
It'll then send you a request of the form `POST /files/<filename>`. The request body will contain the contents of the file.
597+
The tester will then send a `POST` request to the `/files/{filename}` endpoint on your server, with the following parts:
598+
- `Content-Type` header set to `application/octet-stream`.
599+
- `Content-Length` header set to the size of the request body, in bytes.
600+
- Request body set to some random text.
575601
576-
You'll need to fetch the contents of the file from the request body and save it to `<directory>/<filename>`. The response code
577-
returned should be 201.
602+
```
603+
$ curl -v --data "12345" -H "Content-Type: application/octet-stream" http://localhost:4221/files/file_123
604+
```
605+
606+
Your server must return a `201` response:
607+
```
608+
HTTP/1.1 201 Created\r\n\r\n
609+
```
578610
579-
We pass in absolute path to your program using the `--directory` flag.
611+
Your server must also create a new file in the files directory, with the following requirements:
612+
- The filename must equal the `filename` parameter in the endpoint.
613+
- The file must contain the contents of the request body.
580614
581615
{{#reader_is_bot}}
582616
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)