Skip to content

Commit

Permalink
Set x-inngest-expected-server-kind header (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r authored Mar 4, 2024
1 parent 5081aaf commit e835c79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 15 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit e835c79

Please sign in to comment.