本文整理汇总了Golang中github.com/SpectoLabs/hoverfly/core/models.RequestResponsePair.Request方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestResponsePair.Request方法的具体用法?Golang RequestResponsePair.Request怎么用?Golang RequestResponsePair.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/SpectoLabs/hoverfly/core/models.RequestResponsePair
的用法示例。
在下文中一共展示了RequestResponsePair.Request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doRequest
// doRequest performs original request and returns response that should be returned to client and error (if there is one)
func (hf *Hoverfly) doRequest(request *http.Request) (*http.Request, *http.Response, error) {
// We can't have this set. And it only contains "/pkg/net/http/" anyway
request.RequestURI = ""
if hf.Cfg.Middleware.FullCommand != "" {
// middleware is provided, modifying request
var requestResponsePair models.RequestResponsePair
rd, err := models.NewRequestDetailsFromHttpRequest(request)
if err != nil {
return nil, nil, err
}
requestResponsePair.Request = rd
c := NewConstructor(request, requestResponsePair)
err = c.ApplyMiddleware(&hf.Cfg.Middleware)
if err != nil {
log.WithFields(log.Fields{
"mode": hf.Cfg.Mode,
"error": err.Error(),
"host": request.Host,
"method": request.Method,
"path": request.URL.Path,
}).Error("could not forward request, middleware failed to modify request.")
return nil, nil, err
}
request, err = c.ReconstructRequest()
if err != nil {
return nil, nil, err
}
}
requestBody, _ := ioutil.ReadAll(request.Body)
request.Body = ioutil.NopCloser(bytes.NewReader(requestBody))
resp, err := hf.HTTP.Do(request)
request.Body = ioutil.NopCloser(bytes.NewReader(requestBody))
if err != nil {
log.WithFields(log.Fields{
"mode": hf.Cfg.Mode,
"error": err.Error(),
"host": request.Host,
"method": request.Method,
"path": request.URL.Path,
}).Error("could not forward request, failed to do an HTTP request.")
return nil, nil, err
}
log.WithFields(log.Fields{
"mode": hf.Cfg.Mode,
"host": request.Host,
"method": request.Method,
"path": request.URL.Path,
}).Debug("response from external service got successfuly!")
resp.Header.Set("hoverfly", "Was-Here")
return request, resp, nil
}