MCPcopy Index your code
hub / github.com/imroc/req / parseRequestURL

Function parseRequestURL

middleware.go:453–526  ·  view source on GitHub ↗

generate URL

(c *Client, r *Request)

Source from the content-addressed store, hash-verified

451
452// generate URL
453func parseRequestURL(c *Client, r *Request) error {
454 tempURL := r.RawURL
455 if len(r.PathParams) > 0 {
456 for p, v := range r.PathParams {
457 tempURL = strings.Replace(tempURL, "{"+p+"}", url.PathEscape(v), -1)
458 }
459 }
460 if len(c.PathParams) > 0 {
461 for p, v := range c.PathParams {
462 tempURL = strings.Replace(tempURL, "{"+p+"}", url.PathEscape(v), -1)
463 }
464 }
465
466 // Parsing request URL
467 reqURL, err := url.Parse(tempURL)
468 if err != nil {
469 return err
470 }
471
472 if reqURL.Scheme == "" && len(c.scheme) > 0 { // set scheme if missing
473 reqURL, err = url.Parse(c.scheme + "://" + tempURL)
474 if err != nil {
475 return err
476 }
477 }
478
479 // If RawURL is relative path then added c.BaseURL into
480 // the request URL otherwise Request.URL will be used as-is
481 if !reqURL.IsAbs() {
482 tempURL = reqURL.String()
483 if len(tempURL) > 0 && tempURL[0] != '/' {
484 tempURL = "/" + tempURL
485 }
486
487 reqURL, err = url.Parse(c.BaseURL + tempURL)
488 if err != nil {
489 return err
490 }
491 }
492
493 // Adding Query Param
494 query := make(url.Values)
495 for k, v := range c.QueryParams {
496 for _, iv := range v {
497 query.Add(k, iv)
498 }
499 }
500
501 for k, v := range r.QueryParams {
502 // remove query param from client level by key
503 // since overrides happens for that key in the request
504 query.Del(k)
505
506 for _, iv := range v {
507 query.Add(k, iv)
508 }
509 }
510

Callers

nothing calls this directly

Calls 5

IsStringEmptyFunction · 0.92
removeEmptyPortFunction · 0.85
ParseMethod · 0.80
AddMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…