diff --git a/handler.go b/handler.go index 9279dd97..a5d639ac 100644 --- a/handler.go +++ b/handler.go @@ -219,6 +219,12 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { case http.MethodPut: if err := h.register(w, r); err != nil { h.Logger.Error("error registering functions", "error", err.Error()) + + w.WriteHeader(500) + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{ + "message": err.Error(), + }) } return } @@ -357,6 +363,15 @@ func (h *handler) register(w http.ResponseWriter, r *http.Request) error { req.URL.RawQuery = qp.Encode() } + // If the request specifies a server kind then include it as an expectation + // in the outgoing request + if r.Header.Get(HeaderKeyServerKind) != "" { + req.Header.Set( + HeaderKeyExpectedServerKind, + r.Header.Get(HeaderKeyServerKind), + ) + } + key, err := hashedSigningKey([]byte(h.GetSigningKey())) if err != nil { return fmt.Errorf("error creating signing key: %w", err) diff --git a/headers.go b/headers.go index 1bd00fe4..0e64755c 100644 --- a/headers.go +++ b/headers.go @@ -6,14 +6,16 @@ import ( ) const ( - HeaderKeyAuthorization = "Authorization" - HeaderKeyContentType = "Content-Type" - HeaderKeyEnv = "X-Inngest-Env" - HeaderKeyNoRetry = "X-Inngest-No-Retry" - HeaderKeyRetryAfter = "Retry-After" - HeaderKeySDK = "X-Inngest-SDK" - HeaderKeySignature = "X-Inngest-Signature" - HeaderKeyUserAgent = "User-Agent" + HeaderKeyAuthorization = "Authorization" + HeaderKeyContentType = "Content-Type" + HeaderKeyEnv = "X-Inngest-Env" + HeaderKeyExpectedServerKind = "X-Inngest-Expected-Server-Kind" + HeaderKeyNoRetry = "X-Inngest-No-Retry" + HeaderKeyRetryAfter = "Retry-After" + HeaderKeySDK = "X-Inngest-SDK" + HeaderKeyServerKind = "X-Inngest-Server-Kind" + HeaderKeySignature = "X-Inngest-Signature" + HeaderKeyUserAgent = "User-Agent" ) var (