mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-26 01:39:25 +08:00
Centralize shared Comfy API headers in get_comfy_api_headers helper
This commit is contained in:
parent
d3878edb01
commit
b58af4279b
@ -16,9 +16,8 @@ from comfy_api_nodes.util import (
|
|||||||
)
|
)
|
||||||
from comfy_api_nodes.util._helpers import (
|
from comfy_api_nodes.util._helpers import (
|
||||||
default_base_url,
|
default_base_url,
|
||||||
get_auth_header,
|
get_comfy_api_headers,
|
||||||
get_node_id,
|
get_node_id,
|
||||||
get_usage_source,
|
|
||||||
is_processing_interrupted,
|
is_processing_interrupted,
|
||||||
)
|
)
|
||||||
from comfy_api_nodes.util.common_exceptions import ProcessingInterrupted
|
from comfy_api_nodes.util.common_exceptions import ProcessingInterrupted
|
||||||
@ -175,9 +174,7 @@ async def _stream_sonilo_music(
|
|||||||
"""POST ``form`` to Sonilo, read the NDJSON stream, and return the first stream's audio bytes."""
|
"""POST ``form`` to Sonilo, read the NDJSON stream, and return the first stream's audio bytes."""
|
||||||
url = urljoin(default_base_url().rstrip("/") + "/", endpoint.path.lstrip("/"))
|
url = urljoin(default_base_url().rstrip("/") + "/", endpoint.path.lstrip("/"))
|
||||||
|
|
||||||
headers: dict[str, str] = {}
|
headers = get_comfy_api_headers(cls)
|
||||||
headers.update(get_auth_header(cls))
|
|
||||||
headers["Comfy-Usage-Source"] = get_usage_source(cls)
|
|
||||||
headers.update(endpoint.headers)
|
headers.update(endpoint.headers)
|
||||||
|
|
||||||
node_id = get_node_id(cls)
|
node_id = get_node_id(cls)
|
||||||
|
|||||||
@ -9,6 +9,7 @@ from io import BytesIO
|
|||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
|
||||||
from comfy.cli_args import args
|
from comfy.cli_args import args
|
||||||
|
from comfy.deploy_environment import get_deploy_environment
|
||||||
from comfy.model_management import processing_interrupted
|
from comfy.model_management import processing_interrupted
|
||||||
from comfy_api.latest import IO
|
from comfy_api.latest import IO
|
||||||
|
|
||||||
@ -40,6 +41,21 @@ def get_usage_source(node_cls: type[IO.ComfyNode]) -> str:
|
|||||||
return node_cls.hidden.comfy_usage_source or "comfyui-server"
|
return node_cls.hidden.comfy_usage_source or "comfyui-server"
|
||||||
|
|
||||||
|
|
||||||
|
def get_comfy_api_headers(node_cls: type[IO.ComfyNode]) -> dict[str, str]:
|
||||||
|
"""Common headers (auth, deploy environment, usage source) for Comfy API requests.
|
||||||
|
|
||||||
|
Centralizes the shared header set so every Comfy API request sends a consistent
|
||||||
|
set and new shared headers only need to be added in one place. Intended for
|
||||||
|
relative/cloud URLs resolved against ``default_base_url()``; because the result
|
||||||
|
includes auth, callers must not attach it to arbitrary absolute/presigned URLs.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
**get_auth_header(node_cls),
|
||||||
|
"Comfy-Env": get_deploy_environment(),
|
||||||
|
"Comfy-Usage-Source": get_usage_source(node_cls),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def default_base_url() -> str:
|
def default_base_url() -> str:
|
||||||
return getattr(args, "comfy_api_base", "https://api.comfy.org")
|
return getattr(args, "comfy_api_base", "https://api.comfy.org")
|
||||||
|
|
||||||
|
|||||||
@ -19,14 +19,11 @@ from comfy import utils
|
|||||||
from comfy_api.latest import IO
|
from comfy_api.latest import IO
|
||||||
from server import PromptServer
|
from server import PromptServer
|
||||||
|
|
||||||
from comfy.deploy_environment import get_deploy_environment
|
|
||||||
|
|
||||||
from . import request_logger
|
from . import request_logger
|
||||||
from ._helpers import (
|
from ._helpers import (
|
||||||
default_base_url,
|
default_base_url,
|
||||||
get_auth_header,
|
get_comfy_api_headers,
|
||||||
get_node_id,
|
get_node_id,
|
||||||
get_usage_source,
|
|
||||||
is_processing_interrupted,
|
is_processing_interrupted,
|
||||||
sleep_with_interrupt,
|
sleep_with_interrupt,
|
||||||
)
|
)
|
||||||
@ -646,9 +643,7 @@ async def _request_base(cfg: _RequestConfig, expect_binary: bool):
|
|||||||
|
|
||||||
payload_headers = {"Accept": "*/*"} if expect_binary else {"Accept": "application/json"}
|
payload_headers = {"Accept": "*/*"} if expect_binary else {"Accept": "application/json"}
|
||||||
if not parsed_url.scheme and not parsed_url.netloc: # is URL relative?
|
if not parsed_url.scheme and not parsed_url.netloc: # is URL relative?
|
||||||
payload_headers.update(get_auth_header(cfg.node_cls))
|
payload_headers.update(get_comfy_api_headers(cfg.node_cls))
|
||||||
payload_headers["Comfy-Env"] = get_deploy_environment()
|
|
||||||
payload_headers["Comfy-Usage-Source"] = get_usage_source(cfg.node_cls)
|
|
||||||
if cfg.endpoint.headers:
|
if cfg.endpoint.headers:
|
||||||
payload_headers.update(cfg.endpoint.headers)
|
payload_headers.update(cfg.endpoint.headers)
|
||||||
|
|
||||||
|
|||||||
@ -17,8 +17,7 @@ from folder_paths import get_output_directory
|
|||||||
from . import request_logger
|
from . import request_logger
|
||||||
from ._helpers import (
|
from ._helpers import (
|
||||||
default_base_url,
|
default_base_url,
|
||||||
get_auth_header,
|
get_comfy_api_headers,
|
||||||
get_usage_source,
|
|
||||||
is_processing_interrupted,
|
is_processing_interrupted,
|
||||||
sleep_with_interrupt,
|
sleep_with_interrupt,
|
||||||
to_aiohttp_url,
|
to_aiohttp_url,
|
||||||
@ -65,8 +64,7 @@ async def download_url_to_bytesio(
|
|||||||
if cls is None:
|
if cls is None:
|
||||||
raise ValueError("For relative 'cloud' paths, the `cls` parameter is required.")
|
raise ValueError("For relative 'cloud' paths, the `cls` parameter is required.")
|
||||||
url = urljoin(default_base_url().rstrip("/") + "/", url.lstrip("/"))
|
url = urljoin(default_base_url().rstrip("/") + "/", url.lstrip("/"))
|
||||||
headers = get_auth_header(cls)
|
headers = get_comfy_api_headers(cls)
|
||||||
headers["Comfy-Usage-Source"] = get_usage_source(cls)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user