MCPcopy
hub / github.com/cubefs/cubefs / serveRequest

Method serveRequest

cli/api/metaapi.go:112–151  ·  view source on GitHub ↗
(r *request)

Source from the content-addressed store, hash-verified

110type RespBody struct{}
111
112func (c *MetaHttpClient) serveRequest(r *request) (respData []byte, err error) {
113 var resp *http.Response
114 var schema string
115 if c.useSSL {
116 schema = "https"
117 } else {
118 schema = "http"
119 }
120 url := fmt.Sprintf("%s://%s%s", schema, c.host,
121 r.path)
122 resp, err = c.httpRequest(r.method, url, r.params, r.header, r.body)
123 log.LogInfof("resp %v,err %v", resp, err)
124 if err != nil {
125 log.LogErrorf("serveRequest: send http request fail: method(%v) url(%v) err(%v)", r.method, url, err)
126 return
127 }
128 stateCode := resp.StatusCode
129 respData, err = io.ReadAll(resp.Body)
130 _ = resp.Body.Close()
131 if err != nil {
132 log.LogErrorf("serveRequest: read http response body fail: err(%v)", err)
133 return
134 }
135 switch stateCode {
136 case http.StatusOK:
137 body := new(proto.HTTPReplyRaw)
138 if err := body.Unmarshal(respData); err != nil {
139 return nil, err
140 }
141 // o represent proto.ErrCodeSuccess, TODO: 200 ???
142 if body.Code != 200 {
143 return nil, proto.ParseErrorCode(body.Code)
144 }
145 return body.Bytes(), nil
146 default:
147 log.LogErrorf("serveRequest: unknown status: host(%v) uri(%v) status(%v) body(%s).",
148 resp.Request.URL.String(), c.host, stateCode, strings.Replace(string(respData), "\n", "", -1))
149 }
150 return
151}
152
153func (c *MetaHttpClient) httpRequest(method, url string, param, header map[string]string, reqData []byte) (resp *http.Response, err error) {
154 client := http.DefaultClient

Callers 2

GetMetaPartitionMethod · 0.95
GetAllDentryMethod · 0.95

Calls 10

httpRequestMethod · 0.95
LogInfofFunction · 0.92
LogErrorfFunction · 0.92
ParseErrorCodeFunction · 0.92
ReadAllMethod · 0.65
CloseMethod · 0.65
UnmarshalMethod · 0.65
BytesMethod · 0.65
StringMethod · 0.65
ReplaceMethod · 0.45

Tested by

no test coverage detected