Skip to content

Commit 7c44d2b

Browse files
authored
Merge pull request #119 from codecrafters-io/persistence
Add Persistent Connection extension
2 parents 8fb8027 + 72f4e23 commit 7c44d2b

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

course-definition.yml

+97
Original file line numberDiff line numberDiff line change
@@ -822,3 +822,100 @@ stages:
822822
- It's normal for a very short string like `abc` to increase in size when compressed.
823823
marketing_md: |
824824
In this stage, you'll add support for encoding the response body using `gzip`.
825+
826+
- slug: "ag9"
827+
name: "Persistent connection"
828+
difficulty: medium
829+
description_md: |-
830+
In this stage, you'll add support for persistent HTTP connections. By default, HTTP/1.1 connections are persistent, meaning the same TCP connection can be reused for multiple requests.
831+
832+
### Tests
833+
834+
The tester will execute your program like this:
835+
```bash
836+
$ ./your_program.sh
837+
```
838+
839+
The tester will then send two sequential requests over the same connection:
840+
```bash
841+
$ curl --http1.1 -v http://localhost:4221/echo/banana --next http://localhost:4221/user-agent -H "User-Agent: blueberry/apple-blueberry"
842+
```
843+
844+
Your server must:
845+
1. Keep the TCP connection open after the first request
846+
2. Handle any subsequent requests on the same connection
847+
3. Return appropriate responses for both requests
848+
849+
### Notes
850+
- In HTTP/1.1, connections are persistent by default unless the client sends a `Connection: close` header
851+
- Each request must be processed independently, even if they're on the same connection
852+
- The server should not close the connection after each request
853+
854+
marketing_md: |-
855+
In this stage, you'll add support for persistent HTTP connections, allowing multiple requests to be handled over the same TCP connection.
856+
857+
- slug: "ul1"
858+
name: "Multiple persistent connections"
859+
difficulty: medium
860+
description_md: |-
861+
In this stage, you'll extend your server to handle multiple concurrent persistent connections.
862+
863+
### Tests
864+
865+
The tester will execute your program like this:
866+
```bash
867+
$ ./your_program.sh
868+
```
869+
870+
The tester will create two persistent connections and send multiple requests on each:
871+
```bash
872+
$ curl --http1.1 -v http://localhost:4221/user-agent -H "User-Agent: orange/mango-grape" --next http://localhost:4221/echo/apple
873+
```
874+
875+
Your server must:
876+
1. Handle multiple concurrent TCP connections
877+
2. Keep each connection open for multiple requests
878+
3. Process requests independently on each connection
879+
4. Return appropriate responses for all requests
880+
881+
### Notes
882+
- Each connection should be handled independently
883+
- The server should maintain the state of each connection separately
884+
- Requests on different connections can be processed concurrently
885+
886+
marketing_md: |-
887+
In this stage, you'll add support for handling multiple concurrent persistent connections.
888+
889+
- slug: "kh7"
890+
name: "Connection closure"
891+
difficulty: medium
892+
description_md: |-
893+
In this stage, you'll add support for explicit connection closure using the `Connection: close` header.
894+
895+
### Tests
896+
897+
The tester will execute your program like this:
898+
```bash
899+
$ ./your_program.sh
900+
```
901+
902+
The tester will send two requests:
903+
1. A regular request that should keep the connection open
904+
2. A request with `Connection: close` header that should close the connection
905+
906+
```bash
907+
$ curl --http1.1 -v http://localhost:4221/echo/orange --next http://localhost:4221/ -H "Connection: close"
908+
```
909+
910+
Your server must:
911+
1. Keep the connection open after the first request
912+
2. Close the connection after the second request when `Connection: close` is present
913+
3. Include the `Connection: close` header in the response when closing the connection
914+
915+
### Notes
916+
- The `Connection: close` header indicates that the connection should be closed after the response
917+
- The server should include the same header in its response
918+
- After sending the response with `Connection: close`, the server should close the TCP connection
919+
920+
marketing_md: |-
921+
In this stage, you'll add support for explicit connection closure using the Connection header.

0 commit comments

Comments
 (0)