(req *http.Request)
| 23 | } |
| 24 | |
| 25 | func (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 | |
| 49 | func (rm *responseModifier) modifyHTML(html string) string { |
| 50 | parsedURL, err := url.Parse(rm.hub.appURL) |
nothing calls this directly
no test coverage detected