Skip to content

Instantly share code, notes, and snippets.

Avatar

Bogdan Popa Bogdanp

View GitHub Profile
View e2e.patch
From 391facbb5616c4a712b42fd6e60b1852c8f39c45 Mon Sep 17 00:00:00 2001
From: Bogdan Popa <bogdan@defn.io>
Date: Mon, 13 Jan 2020 11:05:11 +0200
Subject: [PATCH] tests: update e2e tests to use safety-limits
---
.../tests/web-server/e2e/file-upload/server.rkt | 8 +++++---
web-server-test/tests/web-server/e2e/json/server.rkt | 4 +++-
.../tests/web-server/e2e/read-write/server.rkt | 6 ++++--
3 files changed, 12 insertions(+), 6 deletions(-)
@Bogdanp
Bogdanp / codesign.sh
Created Jan 1, 2020
Codesigning a Racket executable for inclusion in a macOS app
View codesign.sh
codesign --force \
--timestamp \
--entitlements="$CODE_SIGN_ENTITLEMENTS" \
--sign="$EXPANDED_CODE_SIGN_IDENTITY_NAME" \
-o runtime \
"${PROJECT_DIR}/Resources/core/lib/Racket.framework/Versions/7.5_3m/Racket"
codesign --force \
--timestamp \
--entitlements="$CODE_SIGN_ENTITLEMENTS" \
View web-app-from-scratch-1-14.py
with socket.socket() as server_sock:
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_sock.bind((HOST, PORT))
server_sock.listen(0)
print(f"Listening on {HOST}:{PORT}...")
while True:
client_sock, client_addr = server_sock.accept()
print(f"Received connection from {client_addr}...")
with client_sock:
View web-app-from-scratch-1-13.py
import mimetypes
import os
import socket
import typing
SERVER_ROOT = os.path.abspath("www")
FILE_RESPONSE_TEMPLATE = """\
HTTP/1.1 200 OK
Content-type: {content_type}
View web-app-from-scratch-1-12.py
METHOD_NOT_ALLOWED_RESPONSE = b"""\
HTTP/1.1 405 Method Not Allowed
Content-type: text/plain
Content-length: 17
Method Not Allowed""".replace(b"\n", b"\r\n")
View web-app-from-scratch-1-11.py
NOT_FOUND_RESPONSE = b"""\
HTTP/1.1 404 Not Found
Content-type: text/plain
Content-length: 9
Not Found""".replace(b"\n", b"\r\n")
#...
with socket.socket() as server_sock:
View web-app-from-scratch-1-10.py
BAD_REQUEST_RESPONSE = b"""\
HTTP/1.1 400 Bad Request
Content-type: text/plain
Content-length: 11
Bad Request""".replace(b"\n", b"\r\n")
with socket.socket() as server_sock:
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_sock.bind((HOST, PORT))
View web-app-from-scratch-1-09.py
with socket.socket() as server_sock:
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_sock.bind((HOST, PORT))
server_sock.listen(0)
print(f"Listening on {HOST}:{PORT}...")
while True:
client_sock, client_addr = server_sock.accept()
print(f"Received connection from {client_addr}...")
with client_sock:
View web-app-from-scratch-1-08.py
class Request(typing.NamedTuple):
method: str
path: str
headers: typing.Mapping[str, str]
@classmethod
def from_socket(cls, sock: socket.socket) -> "Request":
"""Read and parse the request from a socket object.
Raises:
View web-app-from-scratch-1-07.py
import typing
class Request(typing.NamedTuple):
method: str
path: str
headers: typing.Mapping[str, str]