Repository navigation
feat: S3 public CDN host like OSS (AI生成) - #104
Merged
Merged
Conversation
S3Uploader.locator_for uses host when set; PUT still signs against endpoint. Empty host keeps url_format. public_base is accepted as an install alias.
pluveto
commented
Sep 1, 2026
| "got {auth}" | ||
| ); | ||
| } | ||
|
|
| # S3 API 端点(AWS 区域 URL 或兼容端点)。 | ||
| endpoint = "https://s3.us-west-2.amazonaws.com" | ||
| # 公开 URL 模板。占位符:{endpoint} {bucket} {path}。 | ||
| # 公开 URL 模板。占位符:{endpoint} {bucket} {path}。host 为空时使用。 |
Owner
Author
There was a problem hiding this comment.
“host 为空时使用。”这种措辞令人费解,不如附带一个例子
Remove the low-value locator tests. Document url_format vs host with concrete printed-URL examples instead of "used when host is empty".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #100
S3 now has the same optional public CDN
hostas Aliyun OSS. Printed locators use that prefix; PUT and SigV4 still targetendpoint. Empty/absenthostkeeps the currenturl_formatbehavior.public_baseis accepted as an install-time alias.Field name
host(matches[uploaders.aliyunoss])public_base(same idea as Qiniu; not a second field onS3Config)locator_forinterpolatesurl_formatas beforeHow to verify
cargo test --workspace --locked cargo clippy --workspace --locked --all-targets -- -D warningslocator_without_host_uses_url_format— default{endpoint}/{bucket}/{path}locator_with_host_uses_cdn_not_endpoint— CDN prefix wins; endpoint/bucket stay out of the public URLsigv4_matches_independent_get_object_vector— signing unchanged (host: String::new())Manual: set
[uploaders.s3] host = "https://cdn.example.com", upload a file, confirm the printed URL ishttps://cdn.example.com/<key>while the PUT still goes toendpoint.Three giants (deliberate)
Eric Evans:
The domain fact is two addresses for one object: the API write target and the public read locator. OSS already says this as
endpointvshost. S3 today folds the public URL intourl_formatinterpolating{endpoint}, so the API address leaks into the locator. The issue asks for OSS language, so the field ishost, notcdn_domain. Callers must not assemble CDN URLs; that stays inside the S3 context.public_baseis Qiniu’s word for the same idea — translate it at install, do not put a second name onS3Config. Empty host is the current model, not a new required concept. No Go 0.2 forward-compat.John Ousterhout:
Design twice. (1) Teach people
url_format = "https://cdn.example.com/{path}"and/or add a{host}placeholder. (2) Optionalhostthat short-circuitslocator_forthe way OSS does. (1) is a shallow module: the config still composes URLs, and it is easy to sign against the CDN by mistake. (2) hides the split; PUT stays onendpoint. Two knobs (host+url_format) is real complexity — accept it only with strict precedence: non-emptyhostwins, empty falls back. Done means locator tests with and without host, the existing SigV4 vector still passes, andput_url/sign_requestnever readhost.Alan Kay:
S3Uploaderis the object.locator_foris the message “what public URL is this key?”.upload/sign_request/put_urlmust not see the CDN host. Do not leak CDN assembly to app, history, or a template the caller has to get right. State:hostis the public prefix,endpointis the API address. Empty host means the object still answers viaurl_format. Late binding: optional host so existing S3 objects keep working.三个人的讨论
Ousterhout: two public-URL mechanisms is over-loose. Users can already set
url_formatto a CDN. Why addhost?Evans: that is not the OSS language the issue asked for.
url_formatstill exposes{endpoint}and{bucket}. Domain experts sayhost.Kay:
url_formatas the only path turns the object into a template engine. The object should answerlocator_for. Host is the better message.Ousterhout: then
hostis acceptable only if PUT is untouched and empty host is a no-op. Reject adding{host}as a third path. Reject makinghostrequired.Evans: a second field
public_baseonS3Configwould split the language. Alias only ats3_from_profile.Kay agrees: install translates; the object’s vocabulary is
host.收敛结论
已收敛. Optional
host: StringonS3Config(empty = absent).locator_forusesjoin_host_path(host, key)when host is non-empty; otherwiseurl_format. PUT/SigV4 useendpointonly.public_basealias ins3_from_profile. Samples document the field. README skipped (S3 fields are not listed there).Rejected:
{host}placeholder inurl_format— shallow; callers still assemblehostlike OSS — breaks existing S3 configsHostheader — signatures would fail; PUT must stay onendpointpublic_baseas a first-classS3Configfield — splits ubiquitous language决策与后续
Decided:
host; install alias:public_baseurl_formatS3Uploader; no caller-side CDN joinResidual risk: a
hostwithout scheme yields a scheme-less locator (same as OSS). Documented withhttps://cdn.example.com.