Compare commits

..

2 Commits

Author SHA1 Message Date
45d197add4
updated nixpkgs 2024-07-05 20:12:49 +02:00
c191f983fe
added header and small fixes 2024-07-05 20:10:03 +02:00
3 changed files with 28 additions and 25 deletions

View File

@ -23,11 +23,11 @@
"systems": "systems_2" "systems": "systems_2"
}, },
"locked": { "locked": {
"lastModified": 1705309234, "lastModified": 1710146030,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -45,11 +45,11 @@
"spectrum": "spectrum" "spectrum": "spectrum"
}, },
"locked": { "locked": {
"lastModified": 1712654305, "lastModified": 1720034501,
"narHash": "sha256-CNdpLnGOUZfIhBanAFVF7t1xstaQGL4w6sQPrVeLlus=", "narHash": "sha256-fzZpuVnhw5uOtA4OuXw3a+Otpy8C+QV0Uu5XfhGEPSg=",
"owner": "astro", "owner": "astro",
"repo": "microvm.nix", "repo": "microvm.nix",
"rev": "ee0068ca87bdabbde3cc39b7af807c0302d0304c", "rev": "a808af7775f508a2afedd1e4940a382fe1194f21",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -81,11 +81,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712608508, "lastModified": 1720031269,
"narHash": "sha256-vMZ5603yU0wxgyQeHJryOI+O61yrX2AHwY6LOFyV1gM=", "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "4cba8b53da471aea2ab2b0c1f30a81e7c451f4b6", "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -106,11 +106,11 @@
"treefmt-nix": "treefmt-nix" "treefmt-nix": "treefmt-nix"
}, },
"locked": { "locked": {
"lastModified": 1708589824, "lastModified": 1719850884,
"narHash": "sha256-2GOiFTkvs5MtVF65sC78KNVxQSmsxtk0WmV1wJ9V2ck=", "narHash": "sha256-UU/lVTHFx0GpEkihoLJrMuM9DcuhZmNe3db45vshSyI=",
"owner": "nix-community", "owner": "nix-community",
"repo": "poetry2nix", "repo": "poetry2nix",
"rev": "3c92540611f42d3fb2d0d084a6c694cd6544b609", "rev": "42262f382c68afab1113ebd1911d0c93822d756e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -194,11 +194,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1708335038, "lastModified": 1719749022,
"narHash": "sha256-ETLZNFBVCabo7lJrpjD6cAbnE11eDOjaQnznmg/6hAE=", "narHash": "sha256-ddPKHcqaKCIFSFc/cvxS14goUhCOAwsM1PbMr0ZtHMg=",
"owner": "numtide", "owner": "numtide",
"repo": "treefmt-nix", "repo": "treefmt-nix",
"rev": "e504621290a1fd896631ddbc5e9c16f4366c9f65", "rev": "8df5ff62195d4e67e2264df0b7f5e8c9995fd0bd",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -1,5 +1,5 @@
{ {
description = "PLACEHOLDER"; description = "A webserver to create files for tetsing purposes";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

View File

@ -44,7 +44,7 @@ class MinSizePerRequestError(Exception):
@api.get('/') @api.get('/')
async def test_data(api_key: str, request: Request, size: str) -> StreamingResponse: async def test_data(api_key: str, 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, request: Request, size: str) -> StreamingRespo
try: try:
size = convert_to_bytes(size) size = convert_to_bytes(size)
except ValueError: except ValueError as err:
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,19 +78,22 @@ async def test_data(api_key: str, request: Request, size: str) -> StreamingRespo
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: except MinSizePerRequestError as err:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE, status_code=status.HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE,
detail=f'Size has to be not-negative.' detail='Size has to be not-negative.'
) ) from err
except MaxSizePerRequestError: except MaxSizePerRequestError as err:
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():