Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn (not error) on content type, by default #227

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

gadomski
Copy link
Member

@gadomski gadomski commented Oct 9, 2024

Related issues and pull requests

Description

@scottyhq any chance you have time to check this one out? I don't have a content_type-non-complaint server at the ready.

@gadomski gadomski self-assigned this Oct 9, 2024
@gadomski gadomski changed the title Warn not error on content type, by default Warn (not error) on content type, by default Oct 9, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.

Project coverage is 83.79%. Comparing base (40b6c71) to head (9c92c6b).

Files with missing lines Patch % Lines
src/stac_asset/http_client.py 36.36% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #227      +/-   ##
==========================================
- Coverage   84.15%   83.79%   -0.37%     
==========================================
  Files          16       16              
  Lines        1073     1080       +7     
==========================================
+ Hits          903      905       +2     
- Misses        170      175       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@scottyhq
Copy link

@scottyhq any chance you have time to check this one out?

Thanks for this! I'll be able to test it out later next week

@drnextgis
Copy link
Contributor

drnextgis commented Oct 23, 2024

👍 for this change! I recently encountered the issue where content_type only returns the content part of the Content-Type header, leading to content type validation fail.

Here's an example in test.py:

import asyncio
from aiohttp import ClientSession

async def fetch_image():
    url = "https://..."
    async with ClientSession() as session:
        async with session.get(url) as response:
            print(response.content_type)
            print(response.headers['Content-Type'])

# Run the async function using asyncio
if __name__ == "__main__":
    asyncio.run(fetch_image())

Output:

$ python test.py
image/tiff
image/tiff; application=geotiff

@gadomski
Copy link
Member Author

@drnextgis thanks! I tried to be permissive about geotiff content types even before this PR, but I forgot about non-cloud-optimized GeoTIFF. I'll add this to PR ... any chance you could check it out, or point me to a server that has this problem so I can test it myself. I haven't dug around to find out yet.

@drnextgis
Copy link
Contributor

Thank you! I can confirm that the warning is triggered when the content type check fails (tested via CLI):

0/8: : 0.00B [00:00, ?B/s, 0 errors]/home/denis/git/stac-asset/src/stac_asset/http_client.py:175: UserWarning: the actual content type does not match the expected: actual=image/tiff1, expected=image/tiff; application=geotiff
  warnings.warn(str(err))

I can also confirm that it no longer fails with image/tiff; application=geotiff.

@gadomski gadomski merged commit 46bc1c4 into main Oct 23, 2024
10 checks passed
@gadomski gadomski deleted the issues/223-warn-on-content-type branch October 23, 2024 12:43
@gadomski
Copy link
Member Author

Released: https://github.com/stac-utils/stac-asset/releases/tag/v0.4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more allowable ContentTypes or make validation optional?
4 participants