-
Notifications
You must be signed in to change notification settings - Fork 97
HTTP CloudEvent coercion #421
Conversation
This reverts commit 45104ce.
187e644 to
f058d1c
Compare
event/request.go
Outdated
| return eventType | ||
| } | ||
|
|
||
| func mapHeadersToEvent(event *Event, headers http.Header) *Event { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename this function to parseAsCloudEventBinary
event/request_test.go
Outdated
| expectedEvent *eventpkg.Event | ||
| }{ | ||
| { | ||
| url: "https://something.eventgateway.com/myspace", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need similar test case for application/json
event/request_test.go
Outdated
| expectedEvent *eventpkg.Event | ||
| }{ | ||
| { | ||
| url: "https://something.eventgateway.com/myspace", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you change that to example.com. For some moment I was confused because I thought it's hosted EG url.
event/request_test.go
Outdated
| CloudEventsVersion: eventpkg.TransformationVersion, | ||
| Source: "/mysource", | ||
| ContentType: "text/plain", | ||
| Data: &eventpkg.HTTPEvent{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this stuct to HTTPRequestData
event/request.go
Outdated
| ) | ||
|
|
||
| const ( | ||
| mimeCloudEventsJSON = "application/cloudevents+json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not used
event/event.go
Outdated
| return nil, errors.New("couldn't cast to []byte") | ||
| } | ||
|
|
||
| func isJSONContent(mime string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename this function to isJSONMimeType?
event/request_test.go
Outdated
| } | ||
| } | ||
|
|
||
| var fromRequestTests = []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need more cases here. also with Event header set
event/request.go
Outdated
| return eventType | ||
| } | ||
|
|
||
| func parseAsCloudEventBinary(event *Event, headers http.Header) *Event { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more request here. It should not get Event as argument. It should be similar to parseAsCloudEvent. So the arguments should be only what's needed which is headers and body []byte. Event should be created inside.
event/http.go
Outdated
|
|
||
| // NewHTTPEvent returns a new instance of HTTPEvent | ||
| func NewHTTPEvent(r *http.Request, eventData interface{}) *HTTPEvent { | ||
| func NewHTTPEvent(r *http.Request, eventData interface{}) *HTTPRequestData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be renamed to NewHTTPRequestData
event/request.go
Outdated
| @@ -0,0 +1,96 @@ | |||
| package event | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move the content of this file to event.go? those file are pretty short and the are basically about the same thing.
Codecov Report
@@ Coverage Diff @@
## master #421 +/- ##
==========================================
+ Coverage 63.87% 63.89% +0.01%
==========================================
Files 29 30 +1
Lines 1650 1681 +31
==========================================
+ Hits 1054 1074 +20
- Misses 553 563 +10
- Partials 43 44 +1
Continue to review full report at Codecov.
|
RaeesBhatti
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| key = strings.TrimLeft(key, "Ce-X-") | ||
| // Make first character lowercase | ||
| runes := []rune(key) | ||
| runes[0] = unicode.ToLower(runes[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HTTP spec says that the header keys are case-insensitive. So, I think it will be better to do a strings.ToLower here for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's true, but in the same time, when you look at the example in HTTP binding spec you will see that desired behavior is to preserve case (testExtension).
Add supports for proper coercion of HTTP and Invoke events to CloudEvent format.
This PR also introduces new CloudEvents processing flow:
400 Bad Request) if not.Todos:
Is this ready for review?: YES
Is it a breaking change?: YES