You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: course-definition.yml
+42-8Lines changed: 42 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -560,23 +560,57 @@ stages:
560
560
In this stage, you'll add support for serving the contents of a file.
561
561
562
562
- slug: "qv8"
563
-
name: "Post a file"
563
+
name: "Read request body"
564
564
difficulty: medium
565
565
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.
567
567
568
-
Just like in the previous stage, the tester will execute your program with a `--directory` flag like this:
568
+
### Request body
569
569
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
570
588
```
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/
572
595
```
573
596
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.
575
601
576
-
You'll need to fetch the contents of the file from the request body and save it to `<directory>/<filename>`. The response code
0 commit comments