MCPcopy
hub / github.com/perkeep/perkeep / discoveryResp

Method discoveryResp

pkg/client/client.go:1029–1054  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

1027}
1028
1029func (c *Client) discoveryResp(ctx context.Context) (*http.Response, error) {
1030 // If the path is just "" or "/", do discovery against
1031 // the URL to see which path we should actually use.
1032 req := c.newRequest(ctx, "GET", c.discoRoot(), nil)
1033 req.Header.Set("Accept", "text/x-camli-configuration")
1034 res, err := c.doReqGated(req)
1035 if err != nil {
1036 return nil, err
1037 }
1038 if res.StatusCode != 200 {
1039 res.Body.Close()
1040 errMsg := fmt.Sprintf("got status %q from blobserver URL %q during configuration discovery", res.Status, c.discoRoot())
1041 if res.StatusCode == http.StatusUnauthorized && c.authErr != nil {
1042 errMsg = fmt.Sprintf("%v. %v", c.authErr, errMsg)
1043 }
1044 return nil, errors.New(errMsg)
1045 }
1046 // TODO(bradfitz): little weird in retrospect that we request
1047 // text/x-camli-configuration and expect to get back
1048 // text/javascript. Make them consistent.
1049 if ct := res.Header.Get("Content-Type"); ct != "text/javascript" {
1050 res.Body.Close()
1051 return nil, fmt.Errorf("Blobserver returned unexpected type %q from discovery", ct)
1052 }
1053 return res, nil
1054}
1055
1056func (c *Client) doDiscovery() error {
1057 ctx := context.TODO()

Callers 2

DiscoveryDocMethod · 0.95
doDiscoveryMethod · 0.95

Calls 6

newRequestMethod · 0.95
discoRootMethod · 0.95
doReqGatedMethod · 0.95
SetMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected