This repository was archived by the owner on Dec 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 1515package main
1616
1717import (
18+ "bytes"
1819 "fmt"
1920 "io/ioutil"
2021 "log"
@@ -148,12 +149,18 @@ func (s *Specification) newTask(w http.ResponseWriter, r *http.Request) {
148149 case result := <- resultsChannel :
149150 log .Printf ("-> %s %d %s\n " , result .id , result .statusCode , result .data )
150151 if s .Sink != "" {
151- ww := w
152- ww .WriteHeader (result .statusCode )
153- ww .Header ().Set ("HOST" , s .Sink )
154- ww .Write (result .data )
155-
156- result .data = []byte ("ok" )
152+ resp , err := http .Post (s .Sink , "application/json" , bytes .NewReader (result .data ))
153+ if err != nil {
154+ msg := fmt .Sprintf ("sink %q is not accepting the request: %s" , s .Sink , err )
155+ log .Printf ("-> ! %s %s\n " , result .id , msg )
156+ result .data = []byte (msg )
157+ result .statusCode = http .StatusBadGateway
158+ } else if resp .StatusCode < 200 || resp .StatusCode > 299 {
159+ msg := fmt .Sprintf ("sink %q responding with the error: %s" , s .Sink , resp .Status )
160+ log .Printf ("-> ! %s %s\n " , result .id , msg )
161+ result .data = []byte (msg )
162+ result .statusCode = resp .StatusCode
163+ }
157164 }
158165 w .WriteHeader (result .statusCode )
159166 w .Write (result .data )
You can’t perform that action at this time.
0 commit comments