Skip to content

Commit 845b7d5

Browse files
author
Suresh Kumar Moharajan
committed
fix missing logic after rebase
Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>
1 parent fa7d046 commit 845b7d5

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

mcpgateway/services/resource_service.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,28 +2961,21 @@ async def update_resource(
29612961
logger.info(f"Auto-detected MIME type for resource {resource_id}: {detected_mime_type}")
29622962
resource.mime_type = detected_mime_type
29632963
else:
2964-
resource.mime_type = resource_update.mime_type
2965-
if resource_update.mime_type is not None or resource_update.uri is not None:
2966-
# Prefer URL-detected MIME type over user-provided to ensure accuracy
2967-
uri_for_detection = resource_update.uri if resource_update.uri is not None else resource.uri
2968-
url_detected_mime = self._detect_mime_type_from_uri(uri_for_detection)
2964+
# Non-empty MIME type: prefer URL-detected over user-provided for security
2965+
uri_for_detection = resource_update.uri if resource_update.uri is not None else resource.uri
2966+
url_detected_mime = self._detect_mime_type_from_uri(uri_for_detection)
29692967

2970-
if url_detected_mime:
2971-
# URL detection successful - use it
2972-
if resource_update.mime_type and resource_update.mime_type != url_detected_mime:
2968+
if url_detected_mime and url_detected_mime != resource_update.mime_type:
29732969
logger.info(f"Using URL-detected MIME type '{url_detected_mime}' instead of user-provided '{resource_update.mime_type}' for resource {resource_id}")
2974-
resource.mime_type = url_detected_mime
2975-
elif resource_update.mime_type is not None:
2976-
# No URL detection, handle user-provided value
2977-
if not resource_update.mime_type:
2978-
# Empty string - fallback to content-based detection
2979-
content_for_detection = resource_update.content if resource_update.content is not None else (resource.text_content or resource.binary_content)
2980-
detected_mime_type = self._detect_mime_type(uri_for_detection, content_for_detection)
2981-
logger.info(f"Fallback MIME type detection for resource {resource_id}: {detected_mime_type}")
2982-
resource.mime_type = detected_mime_type
2970+
resource.mime_type = url_detected_mime
29832971
else:
2984-
# Use user-provided MIME type
2972+
# Use user-provided MIME type if URL detection fails or matches
29852973
resource.mime_type = resource_update.mime_type
2974+
elif resource_update.uri is not None:
2975+
# URI changed but no MIME type provided - try URL detection
2976+
url_detected_mime = self._detect_mime_type_from_uri(resource_update.uri)
2977+
if url_detected_mime:
2978+
resource.mime_type = url_detected_mime
29862979
if resource_update.uri_template is not None:
29872980
resource.uri_template = resource_update.uri_template
29882981
if resource_update.visibility is not None:

0 commit comments

Comments
 (0)