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
2 changes: 1 addition & 1 deletion quickwit.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (c *Client) Search(ctx context.Context, query string, opt *SearchOpt) (*Sea
return nil, err
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint+"/search", bytes.NewReader(reqBody))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, strings.TrimSuffix(c.endpoint, "/")+"/search", bytes.NewReader(reqBody))
if err != nil {
return nil, err
}
Expand Down
26 changes: 26 additions & 0 deletions quickwit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package quickwit_test

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -179,3 +180,28 @@ func TestIngest_OversizeBatchPreservesOrder(t *testing.T) {
}
}
}

// Regression: Search did not strip a trailing slash from the endpoint before appending
// "/search", producing a double-slash URL that many servers/proxies reject.
func TestSearch_TrailingSlashEndpoint(t *testing.T) {
var capturedPath string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
capturedPath = r.URL.Path
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"hits":[],"num_hits":0,"elapsed_time_micros":1}`))
}))
defer server.Close()

// Intentionally add trailing slash to endpoint
c := quickwit.NewClient(server.URL + "/api/v1/test/")
ctx := context.Background()
c.Search(ctx, "*", nil)

if strings.Contains(capturedPath, "//") {
t.Errorf("Search URL contains double slash: %s", capturedPath)
}
if !strings.HasSuffix(capturedPath, "/search") {
t.Errorf("Search URL does not end with /search: %s", capturedPath)
}
}
Loading