Skip to content

Commit 6203203

Browse files
committed
Handle missing trailing slashes better
1 parent c591cd5 commit 6203203

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

webproj/api.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ def __init__(self, src, dst):
131131

132132
if dst not in CRS_LIST.keys():
133133
raise HTTPException(
134-
status_code=status.HTTP_400_BAD_REQUEST,
134+
status_code=status.HTTP_400_BAD_REQUEST,
135135
detail=f"Unknown destination CRS identifier: '{dst}'",
136136
)
137137

138138
src_region = CRS_LIST[src]["country"]
139139
dst_region = CRS_LIST[dst]["country"]
140140
if src_region != dst_region and "Global" not in (src_region, dst_region):
141141
raise HTTPException(
142-
status_code=status.HTTP_400_BAD_REQUEST,
142+
status_code=status.HTTP_400_BAD_REQUEST,
143143
detail="CRS's are not compatible across countries",
144144
)
145145

@@ -302,12 +302,17 @@ class WEBPROJInfo(BaseModel):
302302
proj_version: str
303303

304304

305-
# Set up API entry-points
306-
305+
# Set up API entry-points. Note that some entry-points are duplicated without the trailing /.
306+
# We do this to circumvent implicit redirects made by uvicorn (?) that results
307+
# in URL's that can't be resolved. We do not include those entry-points in the schema.
308+
# It may be possible to do this in a cleaner way by configuring uvicorn differently...
307309

308310
@app.get("/v1.0/crs/")
311+
@app.get("/v1.0/crs", include_in_schema=False)
309312
@app.get("/v1.1/crs/")
313+
@app.get("/v1.1/crs", include_in_schema=False)
310314
@app.get("/v1.2/crs/")
315+
@app.get("/v1.2/crs", include_in_schema=False)
311316
def crs_index() -> CRSList:
312317
"""
313318
List available coordinate reference systems
@@ -505,6 +510,7 @@ async def transformation_4d(
505510

506511

507512
@app.get("/v1.2/info/")
513+
@app.get("/v1.2/info", include_in_schema=False)
508514
async def info() -> WEBPROJInfo:
509515
"""
510516
Retrieve information about the running instance of WEBPROJ and it's constituent components.

0 commit comments

Comments
 (0)