fix: follow environment-document pagination Link headers#11
fix: follow environment-document pagination Link headers#11gagantrivedi merged 1 commit intomainfrom
Conversation
Walk RFC 5988 Link: rel="next" cursors on /environment-document and merge follow-up pages' identity_overrides into the page-1 base. Without this the proxy silently drops every override past the first ~1 MB page and serves stale flag values for affected identities. A single warn! fires per refresh if total fetch time crosses api_poll_frequency_seconds, naming both durations. Refs #10
Zaimwa9
left a comment
There was a problem hiding this comment.
Looks great with one non blocking NIT. It looks like the node implementation if I recall correctly?
Also wondering whether we should have an exit strategy in case the loop never finishes (can it?)
| let base = Url::parse(api_url).ok()?; | ||
|
|
||
| for header_value in headers.get_all(reqwest::header::LINK).iter() { | ||
| let raw = header_value.to_str().ok()?; |
There was a problem hiding this comment.
NIT: maybe over protective but is it worth to continue instead of ok? so an unrelated malformed link doesn't block the whole operation?
There was a problem hiding this comment.
Thought about this one a bit more. The scenario where it'd actually fire is: an upstream emits a Link header value that isn't visible-ASCII (e.g. a 0x80–0xFF byte), and also emits a separate valid rel="next" Link entry that we'd miss because the bad one short-circuits the parse.
RFC 5988 says Link values must be ASCII, and Flagsmith's Edge API today emits one clean Link header per response — single value, no CDN in front rewriting headers. For this corner to bite, you'd need either an upstream bug or a downstream CDN injecting a malformed Link entry before the upstream's clean one. Neither is something we've seen, and Node behaves the same way (its regex match returns null on the same input class — silently treats it as the last page).
Going to leave as ? for now and revisit if we ever do see it in the wild — adding the continue would be one line, but the failure mode it guards against is hypothetical enough that I'd rather not encode "why is this continue?" into the code without a concrete scenario to point at. Happy to reopen if you'd rather have it preemptively though.
|
Thanks for the review! Yep — pretty much the same algorithm as flagsmith-nodejs-client#205. Two small differences worth flagging: the On the loop exit strategy — fair flag. Today there's no explicit page cap; the loop terminates either when there's no
So a truly runaway loop would need an upstream that responds quickly with a |
Summary
Link: rel="next"cursors on/environment-documentand merges follow-up pages'identity_overridesinto the page-1 base.warn!per refresh if total fetch time crossesapi_poll_frequency_seconds, naming both durations.Closes #10. Reference: Flagsmith/flagsmith-nodejs-client#205.
Test plan
cargo test,cargo clippy --all-targets,cargo fmt --checkall clean.