Browse Source

Send correct Content-Type for the JSON body so IFTTT actually notices it

Douglas Thrift 4 days ago
parent
commit
2c12df0dcf
2 changed files with 3 additions and 0 deletions
  1. 1 0
      ifttt/client.go
  2. 2 0
      ifttt/client_test.go

+ 1 - 0
ifttt/client.go

@@ -82,6 +82,7 @@ func (c *client) Trigger(ctx context.Context, present bool) (string, *Values, er
 	if err != nil {
 		return "", nil, err
 	}
+	req.Header.Set("Content-Type", "application/json")
 
 	doer := goahttp.Doer(c.c)
 	if c.debug {

+ 2 - 0
ifttt/client_test.go

@@ -60,6 +60,7 @@ func TestClient_Trigger(t *testing.T) {
 
 					assert.Equal(http.MethodPost, r.Method)
 					assert.Equal("/trigger/"+presentEvent+"/with/key/key", r.URL.Path)
+					assert.Equal("application/json", r.Header.Get("Content-Type"))
 
 					body, err := io.ReadAll(r.Body)
 					assert.NoError(err)
@@ -84,6 +85,7 @@ func TestClient_Trigger(t *testing.T) {
 
 					assert.Equal(http.MethodPost, r.Method)
 					assert.Equal("/trigger/"+absentEvent+"/with/key/key", r.URL.Path)
+					assert.Equal("application/json", r.Header.Get("Content-Type"))
 
 					body, err := io.ReadAll(r.Body)
 					assert.NoError(err)