-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer file extension over content headers (#74)
When determining content type the current behaviour is to trust the `Content-Type` header. However, we have recieved a number of documents with the wrong value set for this. File extensions are arguably slightly more trustworthy then the content type header, so we are opting to prefer it when one matches a supported file type
- Loading branch information
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from requests import Response | ||
import pytest | ||
|
||
from navigator_data_ingest.base.types import CONTENT_TYPE_HTML, CONTENT_TYPE_PDF | ||
from navigator_data_ingest.base.utils import determine_content_type | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("content_type", "source_url", "want"), | ||
( | ||
["text/html", "https://aweb.site/file", CONTENT_TYPE_HTML], | ||
["text/html", "https://aweb.site/file.pdf", CONTENT_TYPE_PDF], | ||
["application/pdf", "https://aweb.site/file", CONTENT_TYPE_PDF], | ||
["application/pdf", "https://aweb.site/file.pdf", CONTENT_TYPE_PDF], | ||
["", "https://aweb.site/file.pdf", CONTENT_TYPE_PDF], | ||
["", "https://aweb.site/file", ""], | ||
) | ||
) | ||
def test_determine_content_type(content_type, source_url, want): | ||
test_response = Response() | ||
test_response.headers["Content-Type"] = content_type | ||
|
||
got = determine_content_type(test_response, source_url) | ||
assert got == want |