MCPcopy Create free account
hub / github.com/coder/coder / RoundTrip

Method RoundTrip

coderd/x/chatd/chatdebug/transport.go:44–118  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

42var _ http.RoundTripper = (*RecordingTransport)(nil)
43
44func (t *RecordingTransport) RoundTrip(req *http.Request) (*http.Response, error) {
45 if req == nil {
46 panic("chatdebug: nil request")
47 }
48
49 base := t.Base
50 if base == nil {
51 base = http.DefaultTransport
52 }
53
54 sink := attemptSinkFromContext(req.Context())
55 if sink == nil {
56 return base.RoundTrip(req)
57 }
58
59 requestHeaders := RedactHeaders(req.Header)
60
61 // Capture method and URL/path from the request.
62 method := req.Method
63 reqURL := ""
64 reqPath := ""
65 if req.URL != nil {
66 reqURL = redactURL(req.URL)
67 reqPath = req.URL.Path
68 }
69
70 requestBody, err := captureRequestBody(req)
71 if err != nil {
72 return nil, err
73 }
74 attemptNumber := sink.nextAttemptNumber()
75
76 startedAt := time.Now()
77 resp, err := base.RoundTrip(req)
78 finishedAt := time.Now()
79 durationMs := finishedAt.Sub(startedAt).Milliseconds()
80 if err != nil {
81 sink.record(Attempt{
82 Number: attemptNumber,
83 Status: attemptStatusFailed,
84 Method: method,
85 URL: reqURL,
86 Path: reqPath,
87 StartedAt: startedAt.UTC().Format(time.RFC3339Nano),
88 FinishedAt: finishedAt.UTC().Format(time.RFC3339Nano),
89 RequestHeaders: requestHeaders,
90 RequestBody: requestBody,
91 Error: sanitizeErrorString(err.Error()),
92 DurationMs: durationMs,
93 })
94 return nil, err
95 }
96
97 respHeaders := RedactHeaders(resp.Header)
98 resp.Body = &recordingBody{
99 inner: resp.Body,
100 sink: sink,
101 startedAt: startedAt,

Callers

nothing calls this directly

Calls 11

attemptSinkFromContextFunction · 0.85
RedactHeadersFunction · 0.85
redactURLFunction · 0.85
captureRequestBodyFunction · 0.85
sanitizeErrorStringFunction · 0.85
nextAttemptNumberMethod · 0.80
ContextMethod · 0.65
FormatMethod · 0.65
GetMethod · 0.65
recordMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected