mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Fix content-type header case sensitivity (#9961)
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
This commit is contained in:
parent
c6e54c83c8
commit
539fc8b760
|
@ -94,7 +94,7 @@ class Response:
|
||||||
@property
|
@property
|
||||||
def is_file(self):
|
def is_file(self):
|
||||||
content_type = self.content_type
|
content_type = self.content_type
|
||||||
content_disposition = self.response.headers.get("Content-Disposition", "")
|
content_disposition = self.response.headers.get("content-disposition", "")
|
||||||
|
|
||||||
return "attachment" in content_disposition or (
|
return "attachment" in content_disposition or (
|
||||||
not any(non_file in content_type for non_file in NON_FILE_CONTENT_TYPES)
|
not any(non_file in content_type for non_file in NON_FILE_CONTENT_TYPES)
|
||||||
|
@ -103,7 +103,7 @@ class Response:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def content_type(self) -> str:
|
def content_type(self) -> str:
|
||||||
return self.headers.get("Content-Type", "")
|
return self.headers.get("content-type", "")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self) -> str:
|
def text(self) -> str:
|
||||||
|
|
|
@ -142,10 +142,11 @@ class HttpRequestNode(BaseNode[HttpRequestNodeData]):
|
||||||
Extract files from response
|
Extract files from response
|
||||||
"""
|
"""
|
||||||
files = []
|
files = []
|
||||||
|
is_file = response.is_file
|
||||||
content_type = response.content_type
|
content_type = response.content_type
|
||||||
content = response.content
|
content = response.content
|
||||||
|
|
||||||
if content_type:
|
if is_file and content_type:
|
||||||
# extract filename from url
|
# extract filename from url
|
||||||
filename = path.basename(url)
|
filename = path.basename(url)
|
||||||
# extract extension if possible
|
# extract extension if possible
|
||||||
|
|
|
@ -430,3 +430,37 @@ def test_multi_colons_parse(setup_http_mock):
|
||||||
assert urlencode({"Redirect": "http://example2.com"}) in result.process_data.get("request", "")
|
assert urlencode({"Redirect": "http://example2.com"}) in result.process_data.get("request", "")
|
||||||
assert 'form-data; name="Redirect"\r\n\r\nhttp://example6.com' in result.process_data.get("request", "")
|
assert 'form-data; name="Redirect"\r\n\r\nhttp://example6.com' in result.process_data.get("request", "")
|
||||||
# assert "http://example3.com" == resp.get("headers", {}).get("referer")
|
# assert "http://example3.com" == resp.get("headers", {}).get("referer")
|
||||||
|
|
||||||
|
|
||||||
|
def test_image_file(monkeypatch):
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"core.tools.tool_file_manager.ToolFileManager.create_file_by_raw",
|
||||||
|
lambda *args, **kwargs: SimpleNamespace(id="1"),
|
||||||
|
)
|
||||||
|
|
||||||
|
node = init_http_node(
|
||||||
|
config={
|
||||||
|
"id": "1",
|
||||||
|
"data": {
|
||||||
|
"title": "http",
|
||||||
|
"desc": "",
|
||||||
|
"method": "get",
|
||||||
|
"url": "https://cloud.dify.ai/logo/logo-site.png",
|
||||||
|
"authorization": {
|
||||||
|
"type": "no-auth",
|
||||||
|
"config": None,
|
||||||
|
},
|
||||||
|
"params": "",
|
||||||
|
"headers": "",
|
||||||
|
"body": None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
result = node._run()
|
||||||
|
assert result.process_data is not None
|
||||||
|
assert result.outputs is not None
|
||||||
|
resp = result.outputs
|
||||||
|
assert len(resp.get("files", [])) == 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user