Skip to content

HTTP Protocol: add RequestData in Context option.#747

Merged
n3wscott merged 1 commit intocloudevents:mainfrom
odacremolbap:task/add-requestdata-context-option
Dec 9, 2021
Merged

HTTP Protocol: add RequestData in Context option.#747
n3wscott merged 1 commit intocloudevents:mainfrom
odacremolbap:task/add-requestdata-context-option

Conversation

@odacremolbap
Copy link
Copy Markdown
Contributor

Closes #742

@n3wscott this is not implemented exactly as described in the issue.

The way I would do this is I would make a context helper in the cloudevents http package, make a new struct with these fields, copy them over before leaving the serve http method into the context using the helper context method.

Instead of adding it at the ServeHTTP method this PR leverages the http.Options, so this feature is an opt-in.

My main concern is that requests will hit the middleware prior to the RateLimiter which feels like the wrong order, but that's the case for all middlewares here. I don't consider that an issue in this PR and if we were to improve the pattern I would suggest moving the RateLimiting feature also as an option (in a different PR).

Signed-off-by: Pablo Mercado <odacremolbap@gmail.com>
@odacremolbap odacremolbap force-pushed the task/add-requestdata-context-option branch from 8c7f727 to 14dc6f3 Compare December 9, 2021 14:08
Copy link
Copy Markdown
Member

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

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

Awesome job!

// WithRequestDataAtContextMiddleware adds to the Context RequestData.
// This enables a user's dispatch handler to inspect HTTP request information by
// retrieving it from the Context.
func WithRequestDataAtContextMiddleware() Option {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice idea!!

@n3wscott n3wscott merged commit 4b69880 into cloudevents:main Dec 9, 2021
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.

CE HTTP: keep request data at the context

2 participants