Skip to content

core: parse task and job IDs from Location header - #4895

Merged
tgeoghegan merged 1 commit into
mainfrom
timg/parse-ids-in-location
Oct 13, 2026
Merged

tgeoghegan merged 1 commit into
mainfrom
timg/parse-ids-in-location

Conversation

@tgeoghegan

Copy link
Copy Markdown
Contributor

Moving toward server-selected resource identifiers means that HTTP clients need to parse resource identifiers from URIs provided by servers in Location HTTP headers.

This adds an extension trait HeaderMapExt with method ids_from_collection_job_location. It finds a Location header and parses its value, extracting the task and collection job IDs.

In the future, we'll need to do this for aggregate shares and aggregation jobs, too, at which point we can make this method generic over types that can be parsed from Base64URL. But for now, we specialize to collection jobs.

@tgeoghegan
tgeoghegan requested a review from a team as a code owner October 13, 2026 13:55
@tgeoghegan

Copy link
Copy Markdown
Contributor Author

This is working towards #4893

Comment thread core/src/retries.rs Outdated
)
})?;

let mut components = location.split("/").collect::<Vec<_>>().into_iter().rev();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified:

Suggested change
let mut components = location.split("/").collect::<Vec<_>>().into_iter().rev();
let mut components = location.rsplit('/');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This saves an allocation, too.

Comment thread core/src/retries.rs Outdated
let mut next_component = || {
components
.next()
.ok_or(HeaderMapExtError::MalformedLocationHeader(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid a clone on the happy path:

Suggested change
.ok_or(HeaderMapExtError::MalformedLocationHeader(
.ok_or_else(|| HeaderMapExtError::MalformedLocationHeader(

Comment thread core/src/retries.rs
Comment on lines +859 to +868
// Malformed middle component
assert_matches!(
header_map(&[(
http::header::LOCATION,
"/tasks/ii_NZYRUHjMI9YCQMmD2ZJNUpLiVz1KHEg-ANpWWnG4/malformed/_Ruk_njErWlidLK2YtFxPA"
)])
.ids_from_collection_job_location()
.unwrap_err(),
HeaderMapExtError::MalformedLocationHeader(..)
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We're missing a test case where the tasks component is replaced with something else.

@tgeoghegan
tgeoghegan force-pushed the timg/parse-ids-in-location branch from aabc80b to 31baf2b Compare October 13, 2026 15:50
@tgeoghegan
tgeoghegan enabled auto-merge (squash) October 13, 2026 15:50
Moving toward server-selected resource identifiers means that HTTP
clients need to parse resource identifiers from URIs provided by servers
in `Location` HTTP headers.

This adds an extension trait `HeaderMapExt` with method
`ids_from_collection_job_location`. It finds a `Location` header and
parses its value, extracting the task and collection job IDs.

In the future, we'll need to do this for aggregate shares and
aggregation jobs, too, at which point we can make this method generic
over types that can be parsed from Base64URL. But for now, we specialize
to collection jobs.
@tgeoghegan
tgeoghegan force-pushed the timg/parse-ids-in-location branch from 31baf2b to ea8e614 Compare October 13, 2026 16:04
@tgeoghegan
tgeoghegan merged commit 00d9eff into main Oct 13, 2026
8 checks passed
@tgeoghegan
tgeoghegan deleted the timg/parse-ids-in-location branch October 13, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants