(ctx context.Context, handler http.Handler, req *http.Request)
| 329 | } |
| 330 | |
| 331 | func handleHTTP(ctx context.Context, handler http.Handler, req *http.Request) (string, error) { |
| 332 | rw := newResponseBuffer() |
| 333 | req = req.WithContext(ctx) |
| 334 | |
| 335 | if req.Body == nil { |
| 336 | req.Body = io.NopCloser(bytes.NewReader([]byte{})) // prevents panic |
| 337 | } |
| 338 | |
| 339 | if req.Header == nil { |
| 340 | req.Header = make(http.Header) |
| 341 | } |
| 342 | |
| 343 | // tell the query frontend we want content formatted for an LLM |
| 344 | req.Header.Set(api.HeaderAccept, api.HeaderAcceptLLM) |
| 345 | |
| 346 | if req.RequestURI == "" { |
| 347 | req.RequestURI = req.URL.RequestURI() |
| 348 | } |
| 349 | |
| 350 | handler.ServeHTTP(rw, req) |
| 351 | |
| 352 | body := rw.body.String() |
| 353 | |
| 354 | if rw.status != http.StatusOK { |
| 355 | return "", fmt.Errorf("tool failed with http status code %d and reason %s", rw.status, body) |
| 356 | } |
| 357 | |
| 358 | return body, nil |
| 359 | } |
| 360 | |
| 361 | // injectMuxVars uses the mux.SetVars method to add vars into the context that can be used by downstream handlers. |
| 362 | // a few Tempo endpoints rely on the mux routing package extracting vars from the request path. this method allows |
no test coverage detected