Skip to content

Commit

Permalink
feat: add True-Client-IP as a custom header to be passed along BAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasLopes7 committed May 31, 2024
1 parent 39bb339 commit 1941c28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ type Params interface {
// CustomRequestHeaders contains predefined values that can be
// used as custom headers in Backend API requests.
type CustomRequestHeaders struct {
Application string
Application string
TrueClientIP string
}

// Apply the custom headers to the HTTP request.
Expand All @@ -169,6 +170,7 @@ func (h *CustomRequestHeaders) apply(req *http.Request) {
return
}
req.Header.Add("X-Clerk-Application", h.Application)
req.Header.Add("X-Clerk-True-Client-IP", h.TrueClientIP)
}

// BackendConfig is used to configure a new Clerk Backend.
Expand Down
4 changes: 3 additions & 1 deletion clerk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func TestBackendCall_RequestHeaders(t *testing.T) {
path := "/resources"
secretKey := "sk_test_123"
customHeaders := CustomRequestHeaders{
Application: "custom-application",
Application: "custom-application",
TrueClientIP: "127.0.0.1",
}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -193,6 +194,7 @@ func TestBackendCall_RequestHeaders(t *testing.T) {
assert.Equal(t, fmt.Sprintf("go/%s", sdkVersion), r.Header.Get("X-Clerk-SDK"))
// Custom headers are added correctly.
assert.Equal(t, customHeaders.Application, r.Header.Get("X-Clerk-Application"))
assert.Equal(t, customHeaders.TrueClientIP, r.Header.Get("X-Clerk-True-Client-IP"))

_, err := w.Write([]byte(`{}`))
require.NoError(t, err)
Expand Down

0 comments on commit 1941c28

Please sign in to comment.