diff options
Diffstat (limited to 'paste/__init__.py')
-rw-r--r-- | paste/__init__.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/paste/__init__.py b/paste/__init__.py index 3ee4468..36ce0cb 100644 --- a/paste/__init__.py +++ b/paste/__init__.py @@ -1,12 +1,13 @@ import binascii import sys import traceback +import urllib.parse from base64 import b64decode, b64encode from collections.abc import Callable, Iterable from functools import wraps from sqlite3 import Connection from typing import Any, Optional, Protocol, runtime_checkable -from wsgiref.util import request_uri +from wsgiref.util import application_uri, request_uri from . import db, store @@ -239,6 +240,24 @@ def application(environ: Env, start_response: StartResponse) -> Response: ], ) return [] + elif environ["REQUEST_METHOD"] == "POST": + content_type = environ.get("CONTENT_TYPE", "text/plain") + content_length = int(environ["CONTENT_LENGTH"]) + content = environ["wsgi.input"].read(content_length) + path, content_hash = store.post(conn, name, content, content_type) + uri = application_uri(environ) + path = urllib.parse.quote(path) + if uri[-1] == "/" and path[:1] == "/": + uri += path[1:] + else: + uri += path + if environ.get("QUERY_STRING"): + uri += "?" + environ["QUERY_STRING"] + start_response( + "201 Created", + [("Location", uri), ("ETag", f'"{b64encode(content_hash).decode()}"')], + ) + return [] elif environ["REQUEST_METHOD"] == "DELETE": if store.delete(conn, name): start_response("204 No Content", []) |