Skip to content

Commit

Permalink
update according to reviewer's advice
Browse files Browse the repository at this point in the history
Signed-off-by: wenfeng <sxian.wang@gmail.com>
  • Loading branch information
wenfengwang committed Jul 21, 2022
1 parent 41e179a commit 3a64bdf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion samples/http/receiver-result/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The CloudEvents Authors
Copyright 2022 The CloudEvents Authors
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
3 changes: 2 additions & 1 deletion samples/http/sender-protobuf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func main() {
var httpResult *cehttp.Result
if cloudevents.ResultAs(res, &httpResult) {
log.Printf("Sent %d with status code %d", i, httpResult.StatusCode)
} else {
log.Printf("Send did not return an HTTP response: %s", res)
}
log.Printf("Send did not return an HTTP response: %s", res)
}
}
}
13 changes: 10 additions & 3 deletions samples/http/sender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/http"

cloudevents "github.com/cloudevents/sdk-go/v2"
cehttp "github.com/cloudevents/sdk-go/v2/protocol/http"
Expand Down Expand Up @@ -41,9 +42,15 @@ func main() {
log.Printf("Failed to send: %v", res)
} else {
var httpResult *cehttp.Result
cloudevents.ResultAs(res, &httpResult)
log.Printf("Sent %d with status code %d, error: %s", i, httpResult.StatusCode,
fmt.Errorf(httpResult.Format, httpResult.Args))
if cloudevents.ResultAs(res, &httpResult) {
var err error
if httpResult.StatusCode != http.StatusOK {
err = fmt.Errorf(httpResult.Format, httpResult.Args...)
}
log.Printf("Sent %d with status code %d, error: %v", i, httpResult.StatusCode, err)
} else {
log.Printf("Send did not return an HTTP response: %s", res)
}
}
}
}
6 changes: 2 additions & 4 deletions v2/protocol/http/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,8 @@ func (p *Protocol) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}

rw.WriteHeader(status)
if errMsg != "" {
if _, err := rw.Write([]byte(errMsg)); err != nil {
return err
}
if _, err := rw.Write([]byte(errMsg)); err != nil {
return err
}
return nil
}
Expand Down

0 comments on commit 3a64bdf

Please sign in to comment.