Skip to content

Conversation

poppoerika
Copy link
Contributor

Make request arg mutable for CacheHeaderInterceptor so that we don't need to create a new request.
Related conversations: #31 (comment)

Copy link
Contributor

@kvcache kvcache left a comment

Choose a reason for hiding this comment

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

thanks for cleaning this up

fn call(
&mut self,
mut request: tonic::Request<()>,
) -> Result<tonic::Request<()>, tonic::Status> {
let request_metadata = request.metadata().clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

do we even need this clone anymore?

Copy link
Contributor Author

@poppoerika poppoerika Apr 7, 2022

Choose a reason for hiding this comment

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

It seems that let cache_name = request.metadata().get("cahce").unwrap() is immutable borrow; therefore request cannot be called with metadata_mut().insert() after that call.
So I think we need to clone first and get cache metadata.

"content-type",
tonic::metadata::AsciiMetadataValue::from_str("application/grpc").unwrap(),
);

let cache_name = request_metadata.get("cache").unwrap();

// need to re-add our `cache` header back into the interceptor or it will be stripped out
Copy link
Contributor

Choose a reason for hiding this comment

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

is this out of date now?

Copy link
Contributor Author

@poppoerika poppoerika Apr 7, 2022

Choose a reason for hiding this comment

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

Good catch! Since we updated to use mutable request directly, it does not seem necessary to add cache back to metadata, which also solve the above comment.
I can just remove this and the above altogether.

@poppoerika poppoerika requested a review from kvcache April 7, 2022 04:59
Copy link
Contributor

@kvcache kvcache left a comment

Choose a reason for hiding this comment

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

Looks good

@poppoerika poppoerika merged commit cbb3b23 into main Apr 7, 2022
@poppoerika poppoerika deleted the chore/cleanUpCacheHeaderInterceptor branch April 7, 2022 16:29
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