MCPcopy Create free account
hub / github.com/compozy/agh / doRequestWithCredentialsAndClient

Method doRequestWithCredentialsAndClient

internal/cli/client.go:5524–5576  ·  view source on GitHub ↗

doRequestWithCredentialsAndClient lets SSE streams opt out of the JSON request timeout.

(
	ctx context.Context,
	method string,
	path string,
	query url.Values,
	requestBody any,
	lastEventID string,
	credentials agentidentity.Credentials,
	client *http.Client,
)

Source from the content-addressed store, hash-verified

5522
5523// doRequestWithCredentialsAndClient lets SSE streams opt out of the JSON request timeout.
5524func (c *unixSocketClient) doRequestWithCredentialsAndClient(
5525 ctx context.Context,
5526 method string,
5527 path string,
5528 query url.Values,
5529 requestBody any,
5530 lastEventID string,
5531 credentials agentidentity.Credentials,
5532 client *http.Client,
5533) (*http.Response, error) {
5534 if ctx == nil {
5535 return nil, errors.New("cli: context is required")
5536 }
5537 if client == nil {
5538 return nil, errors.New("cli: http client is required")
5539 }
5540
5541 target := baseURL + path
5542 if len(query) > 0 {
5543 target += "?" + query.Encode()
5544 }
5545
5546 var body io.Reader
5547 if requestBody != nil {
5548 payload, err := json.Marshal(requestBody)
5549 if err != nil {
5550 return nil, fmt.Errorf("cli: encode %s %s request: %w", method, path, err)
5551 }
5552 body = bytes.NewReader(payload)
5553 }
5554
5555 req, err := http.NewRequestWithContext(ctx, method, target, body)
5556 if err != nil {
5557 return nil, fmt.Errorf("cli: build %s %s request: %w", method, path, err)
5558 }
5559 req.Header.Set("User-Agent", defaultUserAgentName)
5560 if requestBody != nil {
5561 req.Header.Set("Content-Type", "application/json")
5562 }
5563 if strings.TrimSpace(lastEventID) != "" {
5564 req.Header.Set("Last-Event-ID", strings.TrimSpace(lastEventID))
5565 }
5566 setAgentIdentityHeaders(req, credentials)
5567
5568 response, err := client.Do(req)
5569 if err != nil {
5570 if isDaemonUnavailableTransportError(err) {
5571 return nil, newDaemonUnavailableError(c.socketPath, method, path, err)
5572 }
5573 return nil, fmt.Errorf("cli: %s %s via %s: %w", method, path, c.socketPath, err)
5574 }
5575 return response, nil
5576}
5577
5578func newDaemonUnavailableError(socketPath string, method string, path string, err error) error {
5579 item := diagnosticspkg.NewItem(

Callers 3

doSSEMethod · 0.95
doSessionPromptMethod · 0.95

Calls 6

setAgentIdentityHeadersFunction · 0.85
EncodeMethod · 0.65
DoMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected