File
Blob: src/workerd/server/tests/python/sdk/server.py
| 1 | from workers import Blob, FormData, Response, WorkerEntrypoint |
| 2 | |
| 3 | |
| 4 | class Default(WorkerEntrypoint): |
| 5 | async def fetch(self, request): |
| 6 | if request.url.endswith("/sub"): |
| 7 | return Response("Hi there!") |
| 8 | elif request.url.endswith("/sub_headers"): |
| 9 | assert request.headers.get("Custom-Req-Header") == "123" |
| 10 | return Response( |
| 11 | "Hi there!", headers={"Custom-Header-That-Should-Passthrough": True} |
| 12 | ) |
| 13 | elif request.url.endswith("/redirect"): |
| 14 | return Response.redirect("https://example.com/sub", status=301) |
| 15 | elif request.url.endswith("/formdata"): |
| 16 | data = FormData({"field": "value"}) |
| 17 | return Response(data) |
| 18 | elif request.url.endswith("/formdatablob"): |
| 19 | data = FormData({"field": "value"}) |
| 20 | data["blob.py"] = Blob("print(42)", content_type="text/python") |
| 21 | data.append( |
| 22 | "metadata", |
| 23 | Blob("{}", content_type="text/python"), |
| 24 | filename="metadata.json", |
| 25 | ) |
| 26 | return Response(data) |
| 27 | elif request.url.endswith("/ignore"): |
| 28 | # Just a test path that we ignore, used for requests that we don't care about |
| 29 | # the result of. |
| 30 | return Response("ignored") |
| 31 | else: |
| 32 | raise ValueError("Unexpected path " + request.url) |
| 33 | |
| 34 | def test(self): |
| 35 | pass |