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

disconnect context in a dedicated middleware #315

Closed
wants to merge 1 commit into from

Conversation

butonic
Copy link

@butonic butonic commented Oct 10, 2019

Move disconnecting the context to a separate middleware. Deprecates #309

This allows customizing the context that is used for the request handlers by implementing a custom middleware that can eg also add opentracing or other context information.

requires go 1.13 to do a deep copy of the request: https://golang.org/pkg/net/http/#Request.Clone see golang/go#23544 for duscussion and golang/go@f5c43b9 for the commit

@Acconut
Copy link
Member

Acconut commented Oct 10, 2019

To be honest, I am not a huge fan of since since it complicates the request flow even more. Instead, I could think of a creating a new background context which inherits the values from the request's context. Something like this:

type contextWithValues struct {
  context.Context
  valueHolder context.Context
}

func (c contextWithValues) Value(key interface{}) interface{} {
  return c.valueHolder.Value(key)
}

ctxForStorage := contextWithValues{
  // Use background to not get cancel event
  Context: context.Background(),
  // Use request context to get stored values
  valueHolder: request.Context(),
}

requires go 1.13 to do a deep copy of the request: https://golang.org/pkg/net/http/#Request.Clone see golang/go#23544 for duscussion and golang/go@f5c43b9 for the commit

This would also be a problem since we promised to support Go 1.12 until Go 1.14 has been released: https://github.com/tus/tusd/blob/master/docs/installation.md

innovate-invent added a commit to innovate-invent/tusd that referenced this pull request Jan 3, 2020
innovate-invent added a commit to innovate-invent/tusd that referenced this pull request Jan 3, 2020
innovate-invent added a commit to innovate-invent/tusd that referenced this pull request Jan 3, 2020
innovate-invent added a commit to innovate-invent/tusd that referenced this pull request Jan 3, 2020
bastien-seqone pushed a commit to bastien-seqone/tusd that referenced this pull request Jan 12, 2021
@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 Aug 23, 2023
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