> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP(S) 字典源

> 将 HTTP 或 HTTPS 端点配置为 ClickHouse 中的字典源。

如何与 HTTP(S) 服务器交互，取决于[字典在内存中的存储方式](https://clickhouse.com/docs/zh/reference/statements/create/dictionary/layouts/overview.md)。如果字典使用 `cache` 和 `complex_key_cache` 存储，ClickHouse 会通过 `POST` 方法发送请求来获取所需的键。

设置示例：

> [tab] DDL
>
> ```sql theme={null}
> SOURCE(HTTP(
>     url 'http://[::1]/os.tsv'
>     format 'TabSeparated'
>     credentials(user 'user' password 'password')
>     headers(header(name 'API-KEY' value 'key'))
> ))
> ```

> [tab] 配置文件
>
> ```xml theme={null}
> <source>
>     <http>
>         <url>http://[::1]/os.tsv</url>
>         <format>TabSeparated</format>
>         <credentials>
>             <user>user</user>
>             <password>password</password>
>         </credentials>
>         <headers>
>             <header>
>                 <name>API-KEY</name>
>                 <value>key</value>
>             </header>
>         </headers>
>     </http>
> </source>
> ```

要让 ClickHouse 能够访问 HTTPS 资源，必须在服务器配置中[配置 OpenSSL](https://clickhouse.com/docs/zh/reference/settings/server-settings/settings/other.md#openssl)。

设置字段：

| 设置 | 说明 |
| - | - |
| `url` | 源 URL。 |
| `format` | 文件格式。支持 [Formats](https://clickhouse.com/docs/zh/reference/formats/index.md) 中描述的所有格式。 |
| `credentials` | 基本 HTTP 身份验证。可选。 |
| `user` | 身份验证所需的用户名。 |
| `password` | 身份验证所需的密码。 |
| `headers` | HTTP 请求中使用的所有自定义 HTTP 请求头条目。可选。 |
| `header` | 单个 HTTP 请求头条目。 |
| `name` | 请求中发送的请求头名称。 |
| `value` | 为特定名称设置的值。 |

使用 DDL 命令 (`CREATE DICTIONARY ...`) 创建字典时，会根据配置中 `remote_url_allow_hosts` 部分的内容检查 HTTP 字典的远程主机，以防止数据库用户访问任意 HTTP 服务器。

与密码的处理方式相同，请求头 (包括其名称) 在 `SHOW CREATE DICTIONARY` 的输出、`system.tables` 以及查询日志中均显示为 `HEADERS ('[HIDDEN]')`。同样地，无法解析的查询会按原样记录到日志中，仅应用 [`query_masking_rules`](https://clickhouse.com/docs/zh/reference/settings/server-settings/settings/query#query_masking_rules) 进行脱敏。要在 `SHOW CREATE DICTIONARY` 和 `system.tables` 中显示请求头，需要启用服务器设置 [`display_secrets_in_show_and_select`](https://clickhouse.com/docs/zh/reference/settings/server-settings/settings/other#display_secrets_in_show_and_select) 和格式设置 [`format_display_secrets_in_show_and_select`](https://clickhouse.com/docs/zh/reference/settings/formats/format#format_display_secrets_in_show_and_select)；此外，用户还需具有 `displaySecretsInShowAndSelect` 特权。这些设置对查询日志不起作用。
