Skip to content

Commit aa26602

Browse files
committed
fix: explicit error message when no content-type is provided
Signed-off-by: Raphael Glon <[email protected]>
1 parent 963f728 commit aa26602

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/huggingface_inference_toolkit/serialization/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
class ContentType:
3838
@staticmethod
3939
def get_deserializer(content_type: str, task: str):
40+
if not content_type:
41+
message = f"No content type provided and no default one configured."
42+
raise Exception(message)
4043
if content_type.lower().startswith("application/octet-stream"):
4144
if "audio" in task or "speech" in task:
4245
return Audioer

src/huggingface_inference_toolkit/webservice_starlette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def predict(request):
106106
try:
107107
task = request.path_params.get("task", HF_TASK)
108108
# extracts content from request
109-
content_type = request.headers.get("content-Type", os.environ.get("DEFAULT_CONTENT_TYPE")).lower()
109+
content_type = request.headers.get("content-Type", os.environ.get("DEFAULT_CONTENT_TYPE", "")).lower()
110110
# try to deserialize payload
111111
deserialized_body = ContentType.get_deserializer(content_type, task).deserialize(
112112
await request.body()

0 commit comments

Comments
 (0)