dify icon indicating copy to clipboard operation
dify copied to clipboard

Web reader rejects valid pages when Content-Type uses mixed case

Open indexGin opened this issue 3 weeks ago • 3 comments

Phenomenon

The web reader tool refuses to read pages whose HTTP Content-Type header uses a non-lowercase media type. A server returning Content-Type: TEXT/HTML; charset=utf-8 (or Application/JSON, Text/Plain, ...) makes the tool return Unsupported content-type [TEXT/HTML] of URL. instead of fetching and parsing the page. The same URL with a lowercase text/html header works fine.

Minimal reproduction

  1. Use the web reader tool (or call core.tools.utils.web_reader_tool.get_url) on a URL whose server responds with a mixed-case media type, e.g.:

    HTTP/1.1 200 OK
    Content-Type: TEXT/HTML; charset=utf-8
    
  2. Observe the result.

Observed: Unsupported content-type [TEXT/HTML] of URL. Expected: the HTML content is fetched and returned (same as for text/html).

A unit-level reproduction: stub remote_fetcher.make_request to return a 200 response with header Content-Type: APPLICATION/PDF and call get_url(...); the current code returns the "Unsupported content-type" message instead of delegating to ExtractProcessor.load_from_url. The lowercase application/pdf value works correctly.

Expected behavior

HTTP media types are case-insensitive (RFC 9110). TEXT/HTML, Text/Html and text/html must be treated identically. The supported-type check should compare a normalized (lowercased) media type against the list of supported types.

Impact

Users cannot read otherwise valid web pages or documents through the web reader tool when the origin server emits a mixed-case Content-Type — a header form that is fully valid and does occur in the wild. This is a user-visible failure (an "Unsupported content-type" error) on an ordinary input path (following a URL), not an internal edge case. Other parts of the codebase already lowercase this header, so the behavior is also inconsistent.


Additional context (added 2026-11-20, per the maintainer's request)

Dify version / source commit: Not a released build. Verified against the main source tree at commit 29f044b57602e251058925988cba693bbea56370 — the merge base of PR #46379 when it was opened on 2026-11-14.

Cloud or Self Hosted: Self Hosted (Source), i.e. a local source checkout using the repository's own pytest suite. This is a source-only reproduction: it was not observed on a deployed Cloud or Docker instance. The affected code is a pure/shared parsing or serialization helper used by every deployment mode, so the behaviour does not depend on the deployment type. In a running deployment the same helper is reached through normal product paths, but no claim of an observed production incident is made here.

Steps to reproduce:

  1. Check out main at commit 29f044b57602 and enter api/.
  2. Run pytest tests/unit_tests/core/tools/utils/test_web_reader_content_type_case.py -q (regression test added by PR #46379).
  3. Or stub remote_fetcher.make_request to return a response whose header is Content-Type: TEXT/HTML; charset=utf-8 and call core.tools.utils.web_reader_tool.get_url on a sanitized https URL.

✔️ Expected Behavior: A mixed-case media type is treated case-insensitively, exactly like text/html: the HTML is fetched and parsed.

❌ Actual Behavior: The HEAD probe compares the header value case-sensitively and the tool returns Unsupported content-type [TEXT/HTML] of URL. before any GET; the same URL with a lowercase header works.

Complete reproduction: PR #46379 adds api/tests/unit_tests/core/tools/utils/test_web_reader_content_type_case.py plus the fix; running that test file against 29f044b57602e251058925988cba693bbea56370 fails before the fix and passes after it. The exact minimal snippet is also in the issue/PR description.

indexGin avatar Nov 14 '26 08:11 indexGin

The rejection happens during the initial HEAD probe, before either the HTML GET or ExtractProcessor.load_from_url() runs. get_url() strips parameters and whitespace but preserves case, then compares against lowercase supported types. This matches your reproduction without requiring a parsing failure. [1]

The normalization point is the existing header assignment:

main_content_type = content_type.split(";")[0].strip().lower()

That would normalize the value for both the supported-type check and the subsequent extractor dispatch. [2]

Regression coverage can extend the existing HTML-flow and binary-delegation tests in api/tests/unit_tests/core/tools/utils/test_web_reader_tool.py, parameterizing lowercase, uppercase and mixed-case values with parameters. One detail for JSON coverage: the stub_support_types fixture currently includes only PDF and plain text, so it needs application/json added for that case. Keep the existing unsupported image/png assertion as a negative control. [3]

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about dify

dosubot[bot] avatar Nov 14 '26 08:11 dosubot[bot]

Hi @indexGin, thanks for opening this issue.

Why this is being closed

The mixed-case header example and expected result are helpful, but the report does not identify the Dify version or source commit, deployment type, or whether the result was observed through a deployed web reader or only in a unit fixture. The bug report template requests version, deployment and reproduction details. Closing while this context is gathered does not mean the observation is incorrect.

Next steps

Please provide the exact version or commit, deployment type, a reachable sanitized test endpoint or complete local reproduction, and observed versus expected results. If this is source-only, state that explicitly. Once the context is available, please request reopening so the report and linked fix can be reviewed.

crazywoola avatar Nov 20 '26 03:11 crazywoola

The missing bug-report context is now in the issue body: the exact source commit (29f044b57602e251058925988cba693bbea56370), the deployment type, an explicit source-only declaration, step-by-step reproduction commands, and observed versus expected results. I kept the original report intact and only added the details requested in the closing comment.

Requesting that this report be reopened, as suggested. Once it is ready for review, PR #46379 (the fix plus its regression test) can be reassessed. Thank you for the clear checklist — happy to supply anything else that would help.

indexGin avatar Nov 20 '26 07:11 indexGin