Compare commits
No commits in common. "45d197add4d7cfddf09f6531edb8d50e35dc29fd" and "9e83da6b1aa1d185a03d10978a02e10d668fc569" have entirely different histories.
45d197add4
...
9e83da6b1a
30
flake.lock
30
flake.lock
@ -23,11 +23,11 @@
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"lastModified": 1705309234,
|
||||
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -45,11 +45,11 @@
|
||||
"spectrum": "spectrum"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1720034501,
|
||||
"narHash": "sha256-fzZpuVnhw5uOtA4OuXw3a+Otpy8C+QV0Uu5XfhGEPSg=",
|
||||
"lastModified": 1712654305,
|
||||
"narHash": "sha256-CNdpLnGOUZfIhBanAFVF7t1xstaQGL4w6sQPrVeLlus=",
|
||||
"owner": "astro",
|
||||
"repo": "microvm.nix",
|
||||
"rev": "a808af7775f508a2afedd1e4940a382fe1194f21",
|
||||
"rev": "ee0068ca87bdabbde3cc39b7af807c0302d0304c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -81,11 +81,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1720031269,
|
||||
"narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=",
|
||||
"lastModified": 1712608508,
|
||||
"narHash": "sha256-vMZ5603yU0wxgyQeHJryOI+O61yrX2AHwY6LOFyV1gM=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "9f4128e00b0ae8ec65918efeba59db998750ead6",
|
||||
"rev": "4cba8b53da471aea2ab2b0c1f30a81e7c451f4b6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -106,11 +106,11 @@
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719850884,
|
||||
"narHash": "sha256-UU/lVTHFx0GpEkihoLJrMuM9DcuhZmNe3db45vshSyI=",
|
||||
"lastModified": 1708589824,
|
||||
"narHash": "sha256-2GOiFTkvs5MtVF65sC78KNVxQSmsxtk0WmV1wJ9V2ck=",
|
||||
"owner": "nix-community",
|
||||
"repo": "poetry2nix",
|
||||
"rev": "42262f382c68afab1113ebd1911d0c93822d756e",
|
||||
"rev": "3c92540611f42d3fb2d0d084a6c694cd6544b609",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -194,11 +194,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719749022,
|
||||
"narHash": "sha256-ddPKHcqaKCIFSFc/cvxS14goUhCOAwsM1PbMr0ZtHMg=",
|
||||
"lastModified": 1708335038,
|
||||
"narHash": "sha256-ETLZNFBVCabo7lJrpjD6cAbnE11eDOjaQnznmg/6hAE=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "8df5ff62195d4e67e2264df0b7f5e8c9995fd0bd",
|
||||
"rev": "e504621290a1fd896631ddbc5e9c16f4366c9f65",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
description = "A webserver to create files for tetsing purposes";
|
||||
description = "PLACEHOLDER";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
21
src/main.py
21
src/main.py
@ -44,7 +44,7 @@ class MinSizePerRequestError(Exception):
|
||||
|
||||
|
||||
@api.get('/')
|
||||
async def test_data(api_key: str, size: str) -> StreamingResponse:
|
||||
async def test_data(api_key: str, request: Request, size: str) -> StreamingResponse:
|
||||
try:
|
||||
if api_key not in AUTHORIZED_KEYS:
|
||||
raise HTTPException(
|
||||
@ -54,11 +54,11 @@ async def test_data(api_key: str, size: str) -> StreamingResponse:
|
||||
|
||||
try:
|
||||
size = convert_to_bytes(size)
|
||||
except ValueError as err:
|
||||
except ValueError:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='Invalid format format for size.'
|
||||
) from err
|
||||
)
|
||||
|
||||
if size < 0:
|
||||
raise MinSizePerRequestError
|
||||
@ -78,22 +78,19 @@ async def test_data(api_key: str, size: str) -> StreamingResponse:
|
||||
return StreamingResponse(
|
||||
status_code=status.HTTP_200_OK,
|
||||
content=generate_data(size, BUFFER_SIZE),
|
||||
media_type='application/octet-stream',
|
||||
headers={
|
||||
'Content-Length': size
|
||||
}
|
||||
media_type='application/octet-stream'
|
||||
)
|
||||
|
||||
except MinSizePerRequestError as err:
|
||||
except MinSizePerRequestError:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE,
|
||||
detail='Size has to be not-negative.'
|
||||
) from err
|
||||
except MaxSizePerRequestError as err:
|
||||
detail=f'Size has to be not-negative.'
|
||||
)
|
||||
except MaxSizePerRequestError:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE,
|
||||
detail=f'Exceeded max size per request of {MAX_SIZE} Bytes.'
|
||||
) from err
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
|
Loading…
Reference in New Issue
Block a user