Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add True-Client-IP custom header to be passed along to BAPI #298

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ How will this field be used?

The CustomHeaders struct is provided upon the Backend initialization and does not dynamically track values for every request.

See

CustomRequestHeaders: config.CustomRequestHeaders,

The test that's updated in this PR shows exactly this. The value of the x-clerk-true-client-ip header will always be "127.0.0.1" no matter where the request comes from.

Hope I'm not missing anything, but are we sure this PR solves our problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense @gkats, great catch! I'll sync with you tomorrow to understand how can I just pass the headers coming along from a request (if possible). Closing this PR!

}

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Perhaps the "True" portion of the name is a bit too much?

Suggested change
req.Header.Add("X-Clerk-True-Client-IP", h.TrueClientIP)
req.Header.Add("X-Clerk-Client-IP", h.ClientIP)

}

// 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
Loading