Skip to content

Commit

Permalink
Use JSONResponse class throughout
Browse files Browse the repository at this point in the history
There seems to be something up with the ORJSONResponse class when used
with the CORS middleware. If ORJSONResponse is used then the CORS headers
aren't included in the response but if JSONResponse is used then they are.
Pretty weird... Additional bonus is that we really don't need to be using
orjson for this project, speed is not a problem when generating JSON
responses, so binning the orjson stuff makes it simpler and leaves us with
one less dependency :)
  • Loading branch information
jrdh committed Dec 13, 2021
1 parent 7f51659 commit b1def3d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions iiif/routers/iiif.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from fastapi import APIRouter
from fastapi.responses import ORJSONResponse
from starlette.responses import FileResponse
from starlette.responses import FileResponse, JSONResponse

from iiif.ops import IIIF_LEVEL, parse_params
from iiif.processing import Task
Expand All @@ -11,7 +10,7 @@


@router.get('/{identifier}/info.json')
async def get_image_info(identifier: str) -> ORJSONResponse:
async def get_image_info(identifier: str) -> JSONResponse:
"""
IIIF image info endpoint compliant with the specification:
https://iiif.io/api/image/3.0/#22-image-information-request-uri-syntax.
Expand All @@ -30,7 +29,7 @@ async def get_image_info(identifier: str) -> ORJSONResponse:
'cache-control': f'max-age={profile.cache_for}',
'link': f'<http://iiif.io/api/image/3/level{IIIF_LEVEL}.json>;rel="profile"'
}
return ORJSONResponse(content=info_json, headers=headers)
return JSONResponse(content=info_json, headers=headers)


@router.get('/{identifier}/{region}/{size}/{rotation}/{quality}.{fmt}')
Expand Down
6 changes: 3 additions & 3 deletions iiif/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from PIL import Image
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import ORJSONResponse
from starlette.responses import JSONResponse

from iiif.routers import iiif, originals, simple
from iiif.state import state
Expand Down Expand Up @@ -35,7 +35,7 @@ async def on_shutdown():


@app.get('/status')
async def status(full: bool = False) -> ORJSONResponse:
async def status(full: bool = False) -> JSONResponse:
"""
Returns the status of the server along with some stats about current resource usages.
\f
Expand All @@ -53,7 +53,7 @@ async def status(full: bool = False) -> ORJSONResponse:
for profile in state.profiles.values()
}
}
return ORJSONResponse(body, headers={'cache-control': 'no-store'})
return JSONResponse(body, headers={'cache-control': 'no-store'})


# order matters here btw!
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'fastapi~=0.63.0',
'humanize~=3.4.1',
f'jpegtran-cffi @ {jpegtran_url}',
'orjson~=3.5.2',
'pillow~=8.2.0',
'pyyaml~=5.4.1',
'uvicorn[standard]~=0.13.4',
Expand Down

0 comments on commit b1def3d

Please sign in to comment.