Skip to content
Merged
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
6 changes: 3 additions & 3 deletions internal/proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (h *proxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

// gh CLI probes /meta during initialization for feature detection.
// Treat it like GraphQL introspection metadata and pass through unfiltered.
if r.Method == http.MethodGet && rawPath == "/meta" {
// gh CLI probes /meta and /rate_limit during initialization for feature detection
// and connectivity checks. These are safe metadata endpoints — pass through unfiltered.
if r.Method == http.MethodGet && (rawPath == "/meta" || rawPath == "/rate_limit") {
h.passthrough(w, r, fullPath)
return
}
Expand Down
24 changes: 24 additions & 0 deletions internal/proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ func TestServeHTTP_MetaPassthrough(t *testing.T) {
assert.Contains(t, w.Body.String(), "verifiable_password_authentication")
}

func TestServeHTTP_RateLimitPassthrough(t *testing.T) {
receivedURLCh := make(chan string, 1)
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
receivedURLCh <- r.URL.RequestURI()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(`{"resources":{"core":{"limit":5000}}}`))
require.NoError(t, err)
}))
defer upstream.Close()

s := newTestServer(t, upstream.URL)
h := &proxyHandler{server: s}

req := httptest.NewRequest(http.MethodGet, "/api/v3/rate_limit", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, req)

receivedURL := <-receivedURLCh
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "/rate_limit", receivedURL)
assert.Contains(t, w.Body.String(), "core")
}
Comment thread
lpcox marked this conversation as resolved.

// ─── ServeHTTP: write operations (non-GraphQL POST/PUT/DELETE/PATCH) ─────────

func TestServeHTTP_WriteOperationsPassthrough(t *testing.T) {
Expand Down
Loading