Documentation
¶
Overview ¶
Package fetchrss implements the /api/fetch-rss endpoint, used by the RSS / RSSTicker widgets on the Misskey frontend. Fetches a remote RSS or Atom feed and translates it into the Misskey-compatible response shape produced by the upstream TS implementation (which wraps the rss-parser npm package).
Index ¶
Constants ¶
const CacheSeconds = 60 * 3
CacheSeconds matches the upstream Misskey `cacheSec: 60 * 3` declaration so the frontend's browser cache and any reverse-proxy caches behave the same against mk-go and the original TS backend.
const DefaultCacheMaxEntries = 1024
DefaultCacheMaxEntries は in-memory cache が同時に保持するエントリ数の soft cap。攻撃者が大量の異なる URL を送り込むケースで無制限に成長しない よう、超過時は最古 expiresAt のエントリを 1 件 evict する。
1024 は「現実的な widget 設置数 × 同時 actor 数」を超えるが OOM を起こさない 値の経験則。TTL=180s なら 1 URL あたり数 KB 想定で max ~数 MB。
const FetchTimeout = 5 * time.Second
FetchTimeout matches the upstream `timeout: 5000` ms used by Misskey TS.
const MaxBodyBytes int64 = 1 << 20
MaxBodyBytes caps the response read from the upstream feed server.
mk-go は #2106 L27 で先行して 1 MiB に硬化していた。upstream も 2026.7.0 の GHSA hardening で `size: MAX_RESPONSE_SIZE (1 MiB)` を指定するようになり、 現在は完全一致 (乖離解消)。
const MaxConcurrentRequests = 32
MaxConcurrentRequests caps the number of distinct feed URLs being fetched at once (upstream 2026.7.0 MAX_CONCURRENT_REQUESTS = 32). 超過は FETCH_RSS_UNAVAILABLE (503)。同一 URL への合流 (dedup) は上限に数えない。
const MaxURLLength = 8192
MaxURLLength caps the accepted feed URL length (upstream 2026.7.0 MAX_URL_LENGTH = 8192).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves /api/fetch-rss. The HTTP client must be wired with an SSRF-safe transport (see internal/server/outbound_http.go); the handler itself adds only request-shape validation and gofeed translation. Note that safehttp.NewSSRFSafeTransport applies the private-IP guard on every dial, so HTTP redirects to private IPs are also blocked — the handler can rely on the transport for redirect-chain SSRF defense.
Server-side cache: 同 URL への hit は TTL 期間中 in-memory に保持された JSON body を直接書き戻し、upstream へのアクセスは行わない。同じ URL に対する concurrent miss は singleflight で 1 fetch に集約する。エラー レスポンスは cache しない (短期障害がある feed への retry を許す)。
func New ¶
New builds a Handler bound to the given outbound HTTP client and User-Agent string. Pass a client whose Transport is safehttp.NewSSRFSafeTransport(...) so private IPs and non-http(s) schemes never leak through this endpoint. userAgent should normally be cfg.UserAgent so feed servers see the same `Elythia/<ver>` identification used everywhere else.
func (*Handler) DropLocal ¶
func (h *Handler) DropLocal()
DropLocal drops the feeds held by this process (#3776). The concurrency cap (inflight) is not a cache and is kept. 他のプロセスへは伝えない。
func (*Handler) Fetch ¶
Fetch handles GET/POST /api/fetch-rss. The frontend RSS widget uses GET with a query string, so we accept both shapes.
URL 検証と error 体系は upstream 2026.7.0 の GHSA hardening (normalizeUrl + INVALID_URL / FETCH_RSS_FAILED / FETCH_RSS_UNAVAILABLE) に揃える。
func (*Handler) SetCacheMaxEntries ¶
SetCacheMaxEntries overrides the soft cap on in-memory cache entries. 0 以下は無視 (default を維持)。
func (*Handler) SetCacheTTL ¶
SetCacheTTL overrides the server-side cache TTL. Intended for tests; in production the default (CacheSeconds * time.Second) matches the Cache-Control header so client and server see the same freshness window.
func (*Handler) SetClock ¶
SetClock injects a deterministic clock so cache TTL paths can be tested without time.Sleep。
func (*Handler) SetMaxConcurrentFetches ¶
SetMaxConcurrentFetches overrides the distinct-URL concurrency cap. Intended for tests; 0 以下は無視。