This repository was archived by the owner on Dec 11, 2023. It is now read-only.
File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 15
15
package main
16
16
17
17
import (
18
+ "bytes"
18
19
"fmt"
19
20
"io/ioutil"
20
21
"log"
@@ -148,12 +149,18 @@ func (s *Specification) newTask(w http.ResponseWriter, r *http.Request) {
148
149
case result := <- resultsChannel :
149
150
log .Printf ("-> %s %d %s\n " , result .id , result .statusCode , result .data )
150
151
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
+ }
157
164
}
158
165
w .WriteHeader (result .statusCode )
159
166
w .Write (result .data )
You can’t perform that action at this time.
0 commit comments