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

fix: missing error message when return HTTPResult #785

Merged
merged 3 commits into from
Jul 26, 2022

Conversation

wenfengwang
Copy link
Contributor

fix issue #783

@wenfengwang wenfengwang marked this pull request as draft July 20, 2022 13:10
@wenfengwang wenfengwang marked this pull request as ready for review July 20, 2022 13:15
Copy link
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.

Thanks! couple of nits and it LGTM

samples/http/receiver-result/main.go Outdated Show resolved Hide resolved
@@ -390,6 +391,11 @@ func (p *Protocol) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}

rw.WriteHeader(status)
if errMsg != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I believe go does not like to write any body after writing the status header. Can you flip these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your advice @n3wscott . It seems that we have to write body after writing the header. In Go source code https://github.com/golang/go/blob/dev.boringcrypto.go1.18/src/net/http/server.go#L1600, which shows that it will automatically set header when calls Write, and in https://github.com/golang/go/blob/dev.boringcrypto.go1.18/src/net/http/server.go#L1146, which shows that after any WriteHeader called, the flag will be set to true, and in https://github.com/golang/go/blob/dev.boringcrypto.go1.18/src/net/http/server.go#L1140, which checks the flag and if it was the true, the new StatusCode will be ignored. I was wondering if my understanding was right, hope your feedback. : )

Signed-off-by: wenfeng <sxian.wang@gmail.com>
Signed-off-by: wenfeng <sxian.wang@gmail.com>
Signed-off-by: wenfeng <sxian.wang@gmail.com>
@wenfengwang
Copy link
Contributor Author

@n3wscott Hi, please have a look on the PR : )

if res != nil {
var result *Result
switch {
case protocol.ResultAs(res, &result):
if result.StatusCode > 100 && result.StatusCode < 600 {
status = result.StatusCode
}

errMsg = fmt.Errorf(result.Format, result.Args...).Error()
Copy link
Member

Choose a reason for hiding this comment

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

I remember why we did not allow this, we need a way to let the integrator control if the error body is sent or not, some senders expect a cloudevent in response and this will not parse as a cloudevent as a result.

I am in favor of landing this as is but waiting for a release to add an option to control the output format here to let the integrator choose how this error is formatted on return.

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