Skip to content

Commit 0b5d675

Browse files
Merge pull request #4 from hookdeck/cli_text_body_fix
fix: Fix to send data in string_data in case the content-type is text/plain or x-wwww-form-urlencoded
2 parents dfc0c76 + eade751 commit 0b5d675

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

pkg/proxy/proxy.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"io"
89
"io/ioutil"
910
"net/http"
1011
"net/url"
1112
"os"
1213
"os/signal"
1314
"strconv"
15+
"strings"
1416
"syscall"
1517
"time"
1618

@@ -206,7 +208,9 @@ func (p *Proxy) processAttempt(msg websocket.IncomingMessage) {
206208
client := &http.Client{
207209
Timeout: time.Duration(timeout) * time.Millisecond,
208210
}
209-
req, err := http.NewRequest(webhookEvent.Body.Request.Method, url, bytes.NewBuffer(webhookEvent.Body.Request.Data))
211+
fmt.Println(bytes.NewBuffer(webhookEvent.Body.Request.Headers));
212+
213+
req, err := http.NewRequest(webhookEvent.Body.Request.Method, url, nil)
210214
if err != nil {
211215
fmt.Printf("Error: %s\n", err)
212216
return
@@ -217,10 +221,26 @@ func (p *Proxy) processAttempt(msg websocket.IncomingMessage) {
217221
fmt.Printf("Error: %s\n", err)
218222
return
219223
}
224+
225+
bodyIsText := false
226+
220227
for key, value := range x {
221228
unquoted_value, _ := strconv.Unquote(string(value))
222229
req.Header.Set(key, unquoted_value)
230+
231+
if(strings.EqualFold(strings.ToLower(key), strings.ToLower("content-type"))) {
232+
if(strings.Contains(strings.ToLower(string(value)), strings.ToLower("www-form-urlencoded")) || strings.Contains(strings.ToLower(string(value)), strings.ToLower("text/plain"))) {
233+
bodyIsText = true
234+
}
235+
}
223236
}
237+
238+
if bodyIsText {
239+
req.Body = ioutil.NopCloser(strings.NewReader(webhookEvent.Body.Request.DataString))
240+
} else {
241+
req.Body = io.NopCloser(bytes.NewBuffer(webhookEvent.Body.Request.Data))
242+
}
243+
224244
res, err := client.Do(req)
225245
if err != nil {
226246
color := ansi.Color(os.Stdout)

pkg/websocket/attempt_messages.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
)
66

77
type AttemptRequest struct {
8-
Method string `json:"method"`
9-
Timeout int64 `json:"timeout"`
10-
Data json.RawMessage `json:"data"`
11-
Headers json.RawMessage `json:"headers"`
8+
Method string `json:"method"`
9+
Timeout int64 `json:"timeout"`
10+
Data json.RawMessage `json:"data"`
11+
DataString string `json:"data_string"`
12+
Headers json.RawMessage `json:"headers"`
1213
}
1314

1415
type AttemptBody struct {

0 commit comments

Comments
 (0)