Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 2e8e056

Browse files
authored
Merge pull request #37 from triggermesh/empty-body
Support empty body responses
2 parents c69616e + 79c474d commit 2e8e056

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ func getTask(w http.ResponseWriter, r *http.Request) {
176176

177177
w.WriteHeader(http.StatusOK)
178178
w.Write(task.data)
179-
return
180179
}
181180

182181
func initError(w http.ResponseWriter, r *http.Request) {
@@ -187,14 +186,13 @@ func initError(w http.ResponseWriter, r *http.Request) {
187186
defer r.Body.Close()
188187

189188
log.Fatalf("Runtime initialization error: %s\n", data)
190-
return
191189
}
192190

193191
func parsePath(query string) (string, string, error) {
194192
path := strings.TrimPrefix(query, awsEndpoint+"/invocation/")
195193
request := strings.Split(path, "/")
196194
if len(request) != 2 {
197-
return "", "", fmt.Errorf("Incorrect URL query size")
195+
return "", "", fmt.Errorf("incorrect URL query size")
198196
}
199197
return request[0], request[1], nil
200198
}
@@ -240,13 +238,11 @@ func responseHandler(w http.ResponseWriter, r *http.Request) {
240238
statusCode: statusCode,
241239
}
242240
w.WriteHeader(http.StatusAccepted)
243-
return
244241
}
245242

246243
func ping(w http.ResponseWriter, r *http.Request) {
247244
w.WriteHeader(http.StatusOK)
248245
w.Write([]byte("pong"))
249-
return
250246
}
251247

252248
func api() error {

pkg/converter/cloudevents/cloudevents.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ type Overrides struct {
5858
func New() (*CloudEvent, error) {
5959
var ce CloudEvent
6060
if err := envconfig.Process("ce", &ce); err != nil {
61-
return nil, fmt.Errorf("Cannot process CloudEvent env variables: %v", err)
61+
return nil, fmt.Errorf("cannot process CloudEvent env variables: %v", err)
6262
}
6363
return &ce, nil
6464
}
6565

6666
func (ce *CloudEvent) Response(data []byte) ([]byte, error) {
67+
if len(data) == 0 {
68+
return nil, nil
69+
}
70+
6771
if ce.FunctionResponseMode == "event" {
6872
return ce.fillInContext(data)
6973
}

0 commit comments

Comments
 (0)