@@ -38,6 +38,10 @@ func searchDuckDuckGo(ctx context.Context, client *http.Client, query string, ma
3838
3939 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
4040 req.Header.Set("User-Agent", BrowserUserAgent)
41+ req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
42+ req.Header.Set("Accept-Language", "en-US,en;q=0.5")
43+ req.Header.Set("Accept-Encoding", "gzip, deflate")
44+ req.Header.Set("Referer", "https://duckduckgo.com/")
4145
4246 resp, err := client.Do(req)
4347 if err != nil {
@@ -45,8 +49,10 @@ func searchDuckDuckGo(ctx context.Context, client *http.Client, query string, ma
4549 }
4650 defer resp.Body.Close()
4751
48− if resp.StatusCode != http.StatusOK {
49− return nil, fmt.Errorf("search failed with status code: %d", resp.StatusCode)
52+ // Accept both 200 (OK) and 202 (Accepted).
53+ // DuckDuckGo may still return 202 for rate limiting or bot detection.
54+ if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {
55+ return nil, fmt.Errorf("search failed with status code: %d (DuckDuckGo may be rate limiting requests)", resp.StatusCode)
5056 }
5157
5258 body, err := io.ReadAll(resp.Body)