From 95973afb66af591dd9740d7243a9164258587a8a Mon Sep 17 00:00:00 2001 From: Chris Harrelson Date: Fri, 27 Dec 2024 08:39:01 -0800 Subject: [PATCH 1/5] Fix outline for contains_point --- book/outline.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/outline.txt b/book/outline.txt index 02f6d7694..07a5e2083 100644 --- a/book/outline.txt +++ b/book/outline.txt @@ -141,7 +141,7 @@ WIDTH, HEIGHT HSTEP, VSTEP class Rect: def __init__(left, top, right, bottom) - def containsPoint(x, y) + def contains_point(x, y) INPUT_WIDTH_PX IFRAME_WIDTH_PX, IFRAME_HEIGHT_PX BLOCK_ELEMENTS From 1f5f7942c178a5467a9fd389dd724c5a58f89033 Mon Sep 17 00:00:00 2001 From: Chris Harrelson Date: Fri, 27 Dec 2024 09:00:37 -0800 Subject: [PATCH 2/5] Fix save --- infra/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/api.py b/infra/api.py index 50bc255fe..c3f23fe5a 100644 --- a/infra/api.py +++ b/infra/api.py @@ -104,6 +104,7 @@ def set_status(self, i, status): for d in self.data: if d['name'] == self.data[i]['name']: d['status'] = 'denied' + self.save() return self.data[i]['status'] = status self.save() From dffc9d7a2e21c435ac6fcfec756751a24475a2f9 Mon Sep 17 00:00:00 2001 From: Chris Harrelson Date: Fri, 27 Dec 2024 09:19:56 -0800 Subject: [PATCH 3/5] Add connect before for clarity --- book/http.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book/http.md b/book/http.md index c7116ed67..85d8dc4a6 100644 --- a/book/http.md +++ b/book/http.md @@ -842,7 +842,8 @@ Next, we'll wrap the socket with the `ssl` library: class URL: def request(self): # ... - if self.scheme == "https": + s.connect((self.host, self.port)) +p if self.scheme == "https": ctx = ssl.create_default_context() s = ctx.wrap_socket(s, server_hostname=self.host) # ... From 1985ab738f8bae0e56a036b0293ac35f3be9629e Mon Sep 17 00:00:00 2001 From: Chris Harrelson Date: Fri, 27 Dec 2024 09:22:44 -0800 Subject: [PATCH 4/5] add ssl import for clarity --- book/http.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/book/http.md b/book/http.md index 85d8dc4a6..5f1977869 100644 --- a/book/http.md +++ b/book/http.md @@ -803,6 +803,8 @@ Let's try to take this code and add it to `request`. First, we need to detect which scheme is being used: ``` {.python} +import ssl + class URL: def __init__(self, url): self.scheme, url = url.split("://", 1) @@ -843,7 +845,7 @@ class URL: def request(self): # ... s.connect((self.host, self.port)) -p if self.scheme == "https": + if self.scheme == "https": ctx = ssl.create_default_context() s = ctx.wrap_socket(s, server_hostname=self.host) # ... From 2fc1f4d00d49079fe5c8d56c64314365e85f1aef Mon Sep 17 00:00:00 2001 From: Chris Harrelson Date: Fri, 27 Dec 2024 09:30:13 -0800 Subject: [PATCH 5/5] Specify keep-alive in exercise 1-6 --- book/http.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book/http.md b/book/http.md index 5f1977869..ebc4d919b 100644 --- a/book/http.md +++ b/book/http.md @@ -984,7 +984,8 @@ print the entire HTML file as if it was text. You'll want to have also implemented Exercise 1-4. 1-6 *Keep-alive*. Implement Exercise 1-1; however, do not send -the `Connection: close` header. Instead, when reading the body from +the `Connection: close` header (send `Connection: keep-alive` instead). +Instead, when reading the body from the socket, only read as many bytes as given in the `Content-Length` header and don't close the socket afterward. Instead, save the socket, and if another request is made to the same server reuse the