Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing provided HTTP context in UnroutedHandler #443

Closed
bastien-seqone opened this issue Dec 15, 2020 · 5 comments
Closed

Reusing provided HTTP context in UnroutedHandler #443

bastien-seqone opened this issue Dec 15, 2020 · 5 comments

Comments

@bastien-seqone
Copy link

Is your feature request related to a problem? Please describe.
We use tusd with our own store to use the SSE-C functionality of the S3 standard and manage encryption. In order to manage our encryption keys, we have middleware that does a lot of business verification and we would like to pass information through the HTTP context.

But in the UnroutedHandler, the handler methods create a new context (ctx.Background()) and do not reuse the HTTP request context provided (r.Context()).

By example,

// PostFile creates a new file upload using the datastore after validating the
// length and parsing the metadata.
func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) {
	ctx := context.Background() // <- Here
...

Describe the solution you'd like
The Http request context could be used: this would allow middleware to add their own information. I don't believe there is any reason not to use it, but I may have missed something.

Using the same example, it would be :

// PostFile creates a new file upload using the datastore after validating the
// length and parsing the metadata.
func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
...

Describe alternatives you've considered
Using wide available Hashmap, or something like that… but it's not very nice :(

Can you provide help with implementing this feature?
Yep, I think we can manage this little change :)

@Acconut
Copy link
Member

Acconut commented Jan 4, 2021

Thank you for the detailed report. There were already some attempts to reuse the request context but we encountered some issues which are explained in #361 and #309. I am not sure if these would be resolved by now but I am more than happy to help you try it out! :)

@bastien-seqone
Copy link
Author

Sorry I missed the attempts already made.

I've read the solution you propose in the comments in PR #315. I will try to propose something in this way.

@bastien-seqone
Copy link
Author

I have just seen that this that this PR #342 seems to be doing the job.

Can you add a test to ensure that the context values from the HTTP request are actually accessible?

It is this missing test that is blocking its approval?

@Acconut
Copy link
Member

Acconut commented Jan 8, 2021

Yes, this PR is just missing a proper test. However, I would also like to try reusing the request context in such a way that the data storages still work. But that may require some internal refactoring. This would definitely be a better approach instead of such a work around, if you understand what I mean.

@Acconut
Copy link
Member

Acconut commented Aug 23, 2023

Thanks you for your contribution! In tusd v2, the request context will be accessible in the hooks and stores. Please see #986 for more details and #672 for the development of v2.

@Acconut Acconut closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants