Skip to content

Commit

Permalink
fix: remove double quotes and eol from twilio request body
Browse files Browse the repository at this point in the history
  • Loading branch information
splaunov committed Feb 2, 2022
1 parent aeda17d commit 1e01289
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion courier/sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func (c *courier) dispatchSMS(ctx context.Context, msg Message) error {

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
switch res.StatusCode {
case http.StatusOK:
case http.StatusCreated:
default:
return errors.New(http.StatusText(res.StatusCode))
}

Expand Down
12 changes: 8 additions & 4 deletions request/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,20 @@ func (b *Builder) addURLEncodedBody(body interface{}) error {
vm := jsonnet.MakeVM()
vm.TLACode("ctx", buf.String())

res, err := vm.EvaluateAnonymousSnippetMulti(tURL, tpl.String())
res, err := vm.EvaluateAnonymousSnippet(tURL, tpl.String())
if err != nil {
return err
}

values := map[string]string{}
if err := json.Unmarshal([]byte(res), &values); err != nil {
return err
}

u := url.Values{}

for key, value := range res {
v := strings.Replace(value, `\n`, "\n", -1)
u.Add(key, v)
for key, value := range values {
u.Add(key, value)
}

rb := strings.NewReader(u.Encode())
Expand Down
2 changes: 1 addition & 1 deletion request/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestBuildRequest(t *testing.T) {
From: "+13104661805",
Body: "test-sms-body",
},
expectedBody: "Body=%22test-sms-body%22%0A&From=%22%2B13104661805%22%0A&To=%22%2B14134242223%22%0A",
expectedBody: "Body=test-sms-body&From=%2B13104661805&To=%2B14134242223",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint6",
"method": "POST",
Expand Down

0 comments on commit 1e01289

Please sign in to comment.