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