Liking cljdoc? Tell your friends :D

im.ttalk.agent.server.agui.http

routes 每条路外面那一层(C# AguiHttp,A-16 公开):预检、Origin 闸、CORS 回声,外加 JSON / 错误出口 —— 全是 Ring (请求 map 进、响应 map 出)。宿主在自己补的路上用它,⛔ 不用照抄 CORS:

(conj (agui/routes "/agui" host)
      ["POST" "/agui/agent/mine/stop/:threadId"
       (fn [req] (ahttp/guard req host (fn [req] (ahttp/json-response 200 {:stopped true}))))])

与 clj-net-server 的访问守卫(im.ttalk.agent.server.guard)是两层:守卫在路由之前(Host → 预检豁免 → token); 这里在路由之后,只管浏览器那一侧的 Origin / CORS。预检到这里永远 204(403 的预检在浏览器里只报一句 CORS error)。

CORS 缺省拒:带 Origin 的请求一律 403(host 选项 :origin-allowed;用 origin-allow 列白名单,开发时 origin-any)。

`routes` 每条路外面那一层(C# AguiHttp,A-16 公开):预检、Origin 闸、CORS 回声,外加 JSON / 错误出口 —— 全是 Ring
(请求 map 进、响应 map 出)。宿主在自己补的路上用它,⛔ 不用照抄 CORS:

```clojure
(conj (agui/routes "/agui" host)
      ["POST" "/agui/agent/mine/stop/:threadId"
       (fn [req] (ahttp/guard req host (fn [req] (ahttp/json-response 200 {:stopped true}))))])
```

与 clj-net-server 的访问守卫(im.ttalk.agent.server.guard)是两层:守卫在路由之前(Host → 预检豁免 → token);
这里在路由之后,只管浏览器那一侧的 Origin / CORS。预检到这里永远 204(403 的预检在浏览器里只报一句 CORS error)。

CORS 缺省**拒**:带 Origin 的请求一律 403(host 选项 :origin-allowed;用 `origin-allow` 列白名单,开发时 `origin-any`)。
raw docstring

allow-headers-lineclj

(allow-headers-line opts)

默认那串 + 宿主那串(大小写不敏感去重,保序)。⛔ 不写 *:带凭据时浏览器不认通配。

默认那串 + 宿主那串(大小写不敏感去重,保序)。⛔ 不写 *:带凭据时浏览器不认通配。
sourceraw docstring

allow-methods-lineclj

(allow-methods-line thread-store)

mutations 报 true 才列 PATCH / DELETE(浏览器发它们之前要预检);没注册的宿主这一行一个字节不变。

mutations 报 true 才列 PATCH / DELETE(浏览器发它们之前要预检);没注册的宿主这一行一个字节不变。
sourceraw docstring

default-allow-headersclj

预检放行的请求头(默认那串;宿主的 :allow-headers 并在后面,⛔ 不替换:CopilotKit 那几个头是它自己要发的)。

预检放行的请求头(默认那串;宿主的 :allow-headers 并在后面,⛔ 不替换:CopilotKit 那几个头是它自己要发的)。
sourceraw docstring

error-responseclj

(error-response status code message)
(error-response status headers code message)

错误出口:{"error": code, "message": message}(message 可以是 i18n 的 {:code :text})。

错误出口:`{"error": code, "message": message}`(message 可以是 i18n 的 {:code :text})。
sourceraw docstring

guardclj

(guard req host next)

包一条路:OPTIONS ⇒ 预检 204(不调 next);带 Origin 且不在白名单 ⇒ 403 forbidden_origin;否则调 next,把 CORS 头 并进它的响应。白名单、凭据、放行的头与方法都取 host(im.ttalk.agent.server.agui.host)的选项。

包一条路:OPTIONS ⇒ 预检 204(不调 next);带 Origin 且不在白名单 ⇒ 403 `forbidden_origin`;否则调 next,把 CORS 头
并进它的响应。白名单、凭据、放行的头与方法都取 host(im.ttalk.agent.server.agui.host)的选项。
sourceraw docstring

json-responseclj

(json-response status body)
(json-response status headers body)

JSON 出口:状态码 + application/json; charset=utf-8 + 正文(cheshire 编码,保键序)。

JSON 出口:状态码 + `application/json; charset=utf-8` + 正文(cheshire 编码,保键序)。
sourceraw docstring

origin-allowclj

(origin-allow & origins)

白名单谓词(区分大小写,逐字比)。一个都不给 / 有 nil ⇒ 抛 agui-registry/origin-allow-need-one。

白名单谓词(区分大小写,逐字比)。一个都不给 / 有 nil ⇒ 抛 `agui-registry/origin-allow-need-one`。
sourceraw docstring

origin-anyclj

(origin-any)

⚠️⚠️ 只给开发用(生产用 origin-allow 列白名单)。

⚠️⚠️ 只给开发用(生产用 `origin-allow` 列白名单)。
sourceraw docstring

origin-ok?clj

(origin-ok? opts origin)

这个 Origin 放不放行:没有 Origin(curl / 服务端)⇒ 放行;没配谓词 ⇒ 拒;谓词抛 ⇒ 拒。

这个 Origin 放不放行:没有 Origin(curl / 服务端)⇒ 放行;没配谓词 ⇒ 拒;谓词抛 ⇒ 拒。
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close