-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix unneeded cast * added 413 for content over 200kb and 411 if POST without length information * new restriction: maximum 1000 tx ids for search * limit light and full search to 10 * unneeded cast operator * limit TXs to 50
- Loading branch information
Showing
3 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from starlette import status | ||
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint | ||
from starlette.requests import Request | ||
from starlette.responses import Response | ||
|
||
# from https://github.com/tiangolo/fastapi/issues/362 | ||
|
||
class LimitUploadSize(BaseHTTPMiddleware): | ||
def __init__(self, app, max_upload_size: int) -> None: | ||
super().__init__(app) | ||
self.max_upload_size = max_upload_size | ||
|
||
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: | ||
if request.method == 'POST': | ||
if 'content-length' not in request.headers: | ||
return Response(status_code=status.HTTP_411_LENGTH_REQUIRED) | ||
content_length = int(request.headers['content-length']) | ||
if content_length > self.max_upload_size: | ||
return Response(status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE) | ||
return await call_next(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters