MCPcopy
hub / github.com/elastic/go-elasticsearch / Perform

Method Perform

elasticsearch.go:548–593  ·  view source on GitHub ↗

Perform delegates to Transport to execute a request and return a response.

(req *http.Request)

Source from the content-addressed store, hash-verified

546
547// Perform delegates to Transport to execute a request and return a response.
548func (c *BaseClient) Perform(req *http.Request) (*http.Response, error) {
549 if c.isClosed() {
550 return nil, ErrClosed
551 }
552
553 // Compatibility Header
554 if c.compatibilityHeader {
555 if req.Body != nil {
556 req.Header.Set("Content-Type", compatibilityHeader)
557 }
558 req.Header.Set("Accept", compatibilityHeader)
559 }
560
561 if !c.disableMetaHeader {
562 existingMetaHeader := req.Header.Get(HeaderClientMeta)
563 if existingMetaHeader != "" {
564 req.Header.Set(HeaderClientMeta, strings.Join([]string{c.metaHeader, existingMetaHeader}, ","))
565 } else {
566 req.Header.Add(HeaderClientMeta, c.metaHeader)
567 }
568 } else {
569 req.Header.Del(HeaderClientMeta)
570 }
571
572 // Retrieve the original request.
573 res, err := c.Transport.Perform(req)
574 if err != nil {
575 return nil, err
576 }
577
578 // Wrap the response body with auto-draining reader if enabled
579 if c.autoDrainBody && res.Body != nil {
580 res.Body = &autoDrainingReader{res.Body}
581 }
582
583 // ResponseCheck, we run the header check on the first answer from ES.
584 if res.StatusCode >= 200 && res.StatusCode < 300 {
585 checkHeader := func() error { return genuineCheckHeader(res.Header) }
586 if err := c.doProductCheck(checkHeader); err != nil {
587 res.Body.Close()
588 return nil, err
589 }
590 }
591
592 return res, nil
593}
594
595// InstrumentationEnabled propagates back to the client the Instrumentation provided by the transport.
596func (c *BaseClient) InstrumentationEnabled() elastictransport.Instrumentation {

Callers

nothing calls this directly

Calls 9

isClosedMethod · 0.95
doProductCheckMethod · 0.95
genuineCheckHeaderFunction · 0.85
JoinMethod · 0.80
AddMethod · 0.65
PerformMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected