| 389 | var externalDataParams = regexp.MustCompile(`(_types|_structure|_format)$`) |
| 390 | |
| 391 | func (s *scope) decorateRequest(req *http.Request) (*http.Request, url.Values) { |
| 392 | // Make new params to purify URL. |
| 393 | params := make(url.Values) |
| 394 | |
| 395 | // pass ping request |
| 396 | if req.RequestURI == pingEndpoint { |
| 397 | req.URL.Scheme = s.host.Scheme() |
| 398 | req.URL.Host = s.host.Host() |
| 399 | return req, req.URL.Query() |
| 400 | } |
| 401 | |
| 402 | // Set user params |
| 403 | if s.user.params != nil { |
| 404 | for _, param := range s.user.params.params { |
| 405 | params.Set(param.Key, param.Value) |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // Keep allowed params. |
| 410 | origParams := req.URL.Query() |
| 411 | for _, param := range allowedParams { |
| 412 | val := origParams.Get(param) |
| 413 | if len(val) > 0 { |
| 414 | params.Set(param, val) |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // Keep parametrized queries params |
| 419 | for param := range origParams { |
| 420 | if strings.HasPrefix(param, "param_") { |
| 421 | params.Set(param, origParams.Get(param)) |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // Keep external_data params |
| 426 | if req.Method == "POST" { |
| 427 | s.decoratePostRequest(req, origParams, params) |
| 428 | } |
| 429 | |
| 430 | // Set query_id as scope_id to have possibility to kill query if needed. |
| 431 | params.Set("query_id", s.id.String()) |
| 432 | // Set session_timeout an idle timeout for session |
| 433 | params.Set("session_timeout", strconv.Itoa(s.sessionTimeout)) |
| 434 | |
| 435 | req.URL.RawQuery = params.Encode() |
| 436 | |
| 437 | // Rewrite possible previous Basic Auth and send request |
| 438 | // as cluster user. |
| 439 | req.SetBasicAuth(s.clusterUser.name, s.clusterUser.password) |
| 440 | // Delete possible X-ClickHouse headers, |
| 441 | // it is not allowed to use X-ClickHouse HTTP headers and other authentication methods simultaneously |
| 442 | req.Header.Del("X-ClickHouse-User") |
| 443 | req.Header.Del("X-ClickHouse-Key") |
| 444 | |
| 445 | // Send request to the chosen host from cluster. |
| 446 | req.URL.Scheme = s.host.Scheme() |
| 447 | req.URL.Host = s.host.Host() |
| 448 | |