MCPcopy
hub / github.com/henrygd/beszel / RoundTrip

Method RoundTrip

internal/hub/server_development.go:25–47  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

23}
24
25func (rm *responseModifier) RoundTrip(req *http.Request) (*http.Response, error) {
26 resp, err := rm.transport.RoundTrip(req)
27 if err != nil {
28 return resp, err
29 }
30 // Only modify HTML responses
31 contentType := resp.Header.Get("Content-Type")
32 if !strings.Contains(contentType, "text/html") {
33 return resp, nil
34 }
35 body, err := io.ReadAll(resp.Body)
36 if err != nil {
37 return resp, err
38 }
39 resp.Body.Close()
40 // Create a new response with the modified body
41 modifiedBody := rm.modifyHTML(string(body))
42 resp.Body = io.NopCloser(strings.NewReader(modifiedBody))
43 resp.ContentLength = int64(len(modifiedBody))
44 resp.Header.Set("Content-Length", fmt.Sprintf("%d", len(modifiedBody)))
45
46 return resp, nil
47}
48
49func (rm *responseModifier) modifyHTML(html string) string {
50 parsedURL, err := url.Parse(rm.hub.appURL)

Callers

nothing calls this directly

Calls 4

modifyHTMLMethod · 0.95
CloseMethod · 0.65
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected