Skip to content

Instantly share code, notes, and snippets.

From 391facbb5616c4a712b42fd6e60b1852c8f39c45 Mon Sep 17 00:00:00 2001
From: Bogdan Popa <[email protected]>
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 January 1, 2020 22:07
Codesigning a Racket executable for inclusion in a macOS app
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" \
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:
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}
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")
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:
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))
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:
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:
import typing
class Request(typing.NamedTuple):
method: str
path: str
headers: typing.Mapping[str, str]