github.com/anthropics/anthropic-sdk-go@v1.70.1/default_http_client.go (about)

     1  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
     2  
     3  package anthropic
     4  
     5  import (
     6  	"net/http"
     7  	"time"
     8  )
     9  
    10  // defaultResponseHeaderTimeout bounds the time between a fully written request
    11  // and the server's response headers. It does not apply to the response body,
    12  // so long-running streams are unaffected. Without this, a server that accepts
    13  // the connection but never responds would hang the request indefinitely.
    14  const defaultResponseHeaderTimeout = 10 * time.Minute
    15  
    16  // defaultHTTPClient returns an [*http.Client] used when the caller does not
    17  // supply one via [option.WithHTTPClient]. When [http.DefaultTransport] is the
    18  // stdlib [*http.Transport], it is cloned and a [http.Transport.ResponseHeaderTimeout]
    19  // is set so stuck connections fail fast instead of compounding across retries.
    20  // If [http.DefaultTransport] has been wrapped (for example by otelhttp for
    21  // distributed tracing), the wrapping is preserved and the header timeout is
    22  // skipped.
    23  func defaultHTTPClient() *http.Client {
    24  	if t, ok := http.DefaultTransport.(*http.Transport); ok {
    25  		t = t.Clone()
    26  		t.ResponseHeaderTimeout = defaultResponseHeaderTimeout
    27  		return &http.Client{Transport: t}
    28  	}
    29  	return &http.Client{Transport: http.DefaultTransport}
    30  }