// BuildHTTPRequest builds http request with an operation and an input.
977823
func (qb *QingStorBuilder) BuildHTTPRequest(o *data.Operation, i *reflect.Value) (*http.Request, error) {
	qb.baseBuilder = &BaseBuilder{}
	qb.baseBuilder.operation = o
	qb.baseBuilder.input = i

	_, err := qb.baseBuilder.parse()
	if err != nil {
		return nil, err
	}
	err = qb.parseURL()
	if err != nil {
		return nil, err
	}

	httpRequest, err := http.NewRequest(qb.baseBuilder.operation.RequestMethod,
		qb.baseBuilder.parsedURL, qb.baseBuilder.parsedBody)
	if err != nil {
		return nil, err
	}

	err = qb.baseBuilder.setupHeaders(httpRequest)
	if err != nil {
		return nil, err
	}
	err = qb.setupHeaders(httpRequest)
	if err != nil {
		return nil, err
	}

	logger.Infof(nil, fmt.Sprintf(
		"Built QingStor request: [%d] %s",
		convert.StringToTimestamp(httpRequest.Header.Get("Date"), convert.RFC822),
		httpRequest.URL.String(),
	))

	logger.Infof(nil, fmt.Sprintf(
		"QingStor request headers: [%d] %s",
		convert.StringToTimestamp(httpRequest.Header.Get("Date"), convert.RFC822),
		fmt.Sprint(httpRequest.Header),
	))

	if qb.baseBuilder.parsedBodyString != "" {
		logger.Infof(nil, fmt.Sprintf(
			"QingStor request body string: [%d] %s",
			convert.StringToTimestamp(httpRequest.Header.Get("Date"), convert.RFC822),
			qb.baseBuilder.parsedBodyString,
		))
	}

	return httpRequest, nil
}
94655
func newHTTPRequest(path string, data io.Reader) (*http.Request, error) {
	if !strings.HasPrefix(path, "/") {
		path = "/" + path
	}
	req, err := http.NewRequest("POST", path, data)
	if err != nil {
		return nil, err
	}
	req.Header.Add("Accept", VersionMimetype)
	return req, nil
}
294823
func Convert_v1_BuildRequest_To_build_BuildRequest(in *v1.BuildRequest, out *build.BuildRequest, s conversion.Scope) error {
	return autoConvert_v1_BuildRequest_To_build_BuildRequest(in, out, s)
}
1235646
func BuildAsGET(r *request.Request) {
	if r.ParamsFilled() {
		v := reflect.ValueOf(r.Params).Elem()
		buildLocationElements(r, v, true)
		buildBody(r, v)
	}
}
1358210
func (s *ValidateService) buildURL() (string, url.Values, error) {
	var err error
	var path string
	// Build URL
	if len(s.index) > 0 && len(s.typ) > 0 {
		path, err = uritemplates.Expand("/{index}/{type}/_validate/query", map[string]string{
			"index": strings.Join(s.index, ","),
			"type":  strings.Join(s.typ, ","),
		})
	} else if len(s.index) > 0 {
		path, err = uritemplates.Expand("/{index}/_validate/query", map[string]string{
			"index": strings.Join(s.index, ","),
		})
	} else {
		path, err = uritemplates.Expand("/_validate/query", map[string]string{
			"type": strings.Join(s.typ, ","),
		})
	}
	if err != nil {
		return "", url.Values{}, err
	}

	// Add query string parameters
	params := url.Values{}
	if s.pretty {
		params.Set("pretty", "true")
	}
	if s.explain != nil {
		params.Set("explain", fmt.Sprintf("%v", *s.explain))
	}
	if s.rewrite != nil {
		params.Set("rewrite", fmt.Sprintf("%v", *s.rewrite))
	}
	if s.allShards != nil {
		params.Set("all_shards", fmt.Sprintf("%v", *s.allShards))
	}
	if s.defaultOperator != "" {
		params.Set("default_operator", s.defaultOperator)
	}
	if s.lenient != nil {
		params.Set("lenient", fmt.Sprintf("%v", *s.lenient))
	}
	if s.q != "" {
		params.Set("q", s.q)
	}
	if s.analyzeWildcard != nil {
		params.Set("analyze_wildcard", fmt.Sprintf("%v", *s.analyzeWildcard))
	}
	if s.analyzer != "" {
		params.Set("analyzer", s.analyzer)
	}
	if s.df != "" {
		params.Set("df", s.df)
	}
	if s.allowNoIndices != nil {
		params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
	}
	if s.expandWildcards != "" {
		params.Set("expand_wildcards", s.expandWildcards)
	}
	if s.ignoreUnavailable != nil {
		params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
	}
	return path, params, nil
}
248600
func (e *Expect) Request(method, path string, pathargs ...interface{}) *Request {
	req := NewRequest(e.config, method, path, pathargs...)

	for _, builder := range e.builders {
		builder(req)
	}

	for _, matcher := range e.matchers {
		req.WithMatcher(matcher)
	}

	return req
}
1007982
func (rc *httpClient) buildMarathonJSONRequest(method, member, path string, reader io.Reader) (request *http.Request, err error) {
	req, err := rc.buildMarathonRequest(method, member, path, reader)
	if err == nil {
		req.Header.Add("Content-Type", "application/json")
		req.Header.Add("Accept", "application/json")
	}

	return req, err
}
958924
func (a *AgentServer) BuildHost(request BuildHostRequest, hostResponse *host.Host) error {
	*hostResponse = host.Host{}

	h, err := host.Build(request.IP, fmt.Sprintf("%d", request.Port), request.PoolID, request.Memory, a.staticIPs...)
	if err != nil {
		return err
	}

	plog.WithFields(logrus.Fields{
		"poolid": request.PoolID,
		"staticips": a.staticIPs,
		"ipcount": len(a.staticIPs),
	}).Info("Built Host record")
	if h != nil {
		*hostResponse = *h
	}
	return nil
}
882394
func (r *Request) HTTPRequest() (*http.Request, error) {
	req, err := http.NewRequest(string(r.Method), r.URL.String(), nil)
	if err != nil {
		return nil, err
	}

	// merge headers
	req.Header = r.Headers

	// generate the body
	if r.prepare != nil {
		if err := r.prepare(req); err != nil {
			return nil, err
		}
	}

	return req, nil
}
611173
func (rc *httpClient) buildMarathonRequest(method, member, path string, reader io.Reader) (request *http.Request, err error) {
	if strings.HasPrefix(path, "/") {
		panic(fmt.Sprintf("Path '%s' must not start with a leading slash", path))
	}

	// Create the endpoint URL
	url := fmt.Sprintf("%s/%s", member, path)

	// Instantiate an HTTP request
	request, err = http.NewRequest(method, url, reader)
	if err != nil {
		return nil, err
	}

	// Add any basic auth and the content headers
	if rc.config.HTTPBasicAuthUser != "" && rc.config.HTTPBasicPassword != "" {
		request.SetBasicAuth(rc.config.HTTPBasicAuthUser, rc.config.HTTPBasicPassword)
	}

	if rc.config.DCOSToken != "" {
		request.Header.Add("Authorization", "token="+rc.config.DCOSToken)
	}

	return request, nil
}
722985
func (self *Surf) buildClient(param *Param) *http.Client {
	client := &http.Client{
		CheckRedirect: param.checkRedirect,
	}

	if param.enableCookie {
		client.Jar = self.CookieJar
	}

	transport := &http.Transport{
		Dial: func(network, addr string) (net.Conn, error) {
			var (
				c          net.Conn
				err        error
				ipPort, ok = dnsCache.Query(addr)
			)
			if !ok {
				ipPort = addr
				defer func() {
					if err == nil {
						dnsCache.Reg(addr, c.RemoteAddr().String())
					}
				}()
			} else {
				defer func() {
					if err != nil {
						dnsCache.Del(addr)
					}
				}()
			}
			c, err = net.DialTimeout(network, ipPort, param.dialTimeout)
			if err != nil {
				return nil, err
			}
			if param.connTimeout > 0 {
				c.SetDeadline(time.Now().Add(param.connTimeout))
			}
			return c, nil
		},
	}

	if param.proxy != nil {
		transport.Proxy = http.ProxyURL(param.proxy)
	}

	if strings.ToLower(param.url.Scheme) == "https" {
		transport.TLSClientConfig = &tls.Config{RootCAs: nil, InsecureSkipVerify: true}
		transport.DisableCompression = true
	}
	client.Transport = transport
	return client
}
368680
func makeHttpRequest(pcc *PubControlClient, uri, authHeader string,
	jsonContent []byte) (int, []byte, error) {
	var req *http.Request
	req, err := http.NewRequest("POST", uri, bytes.NewReader(jsonContent))
	if err != nil {
		return 0, nil, err
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", authHeader)
	resp, err := pcc.httpClient.Do(req)
	if err != nil {
		return 0, nil, err
	}
	defer resp.Body.Close()
	var body []byte
	body, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return 0, nil, err
	}
	return resp.StatusCode, body, nil
}
1141457
func (service *WebSocketService) ServeHTTP(
	response http.ResponseWriter, request *http.Request) {
	if request.Method == "GET" && !strings.Contains(strings.ToLower(request.Header.Get("connection")), "upgrade") || request.Method == "POST" || request.Method == "OPTIONS" {
		service.HTTPService.ServeHTTP(response, request)
		return
	}
	conn, err := service.Upgrade(response, request, nil)
	if err != nil {
		context := new(rpc.HTTPContext)
		context.InitHTTPContext(service, response, request)
		resp := service.EndError(err, context)
		response.Header().Set("Content-Length", util.Itoa(len(resp)))
		response.Write(resp)
		return
	}
	defer conn.Close()

	mutex := new(sync.Mutex)
	for {
		msgType, data, err := conn.ReadMessage()
		if err != nil {
			break
		}
		if msgType == websocket.BinaryMessage {
			go service.handle(data, mutex, response, request, conn)
		}
	}
}
223481
func (bow *Browser) buildClient() *http.Client {
	return &http.Client{
		CheckRedirect: bow.shouldRedirect,
	}
}
215168
func BuildRequest(token, method, url string, body io.Reader) (*http.Request, error) {
	req, err := http.NewRequest(method, url, body)
	if err != nil {
		return nil, err
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	return req, nil
}
1006834
func (m *Manager) BuildHTTP(rootCtx context.Context, serviceName string, responseModifier func(*http.Response) error) (http.Handler, error) {
	ctx := log.With(rootCtx, log.Str(log.ServiceName, serviceName))

	serviceName = internal.GetQualifiedName(ctx, serviceName)
	ctx = internal.AddProviderInContext(ctx, serviceName)

	if conf, ok := m.configs[serviceName]; ok {
		// TODO Should handle multiple service types
		// FIXME Check if the service is declared multiple times with different types
		if conf.LoadBalancer != nil {
			return m.getLoadBalancerServiceHandler(ctx, serviceName, conf.LoadBalancer, responseModifier)
		}
		return nil, fmt.Errorf("the service %q doesn't have any load balancer", serviceName)
	}
	return nil, fmt.Errorf("the service %q does not exits", serviceName)
}
349829
func CreateHTTPUpload(req HTTPTransferRequest) (Command, error) {
	if req.HTTPRequest == nil {
		return nil, trace.BadParameter("missing parameter HTTPRequest")
	}

	if req.FileName == "" {
		return nil, trace.BadParameter("missing file name")
	}

	if req.RemoteLocation == "" {
		return nil, trace.BadParameter("missing remote location")
	}

	contentLength := req.HTTPRequest.Header.Get("Content-Length")
	fileSize, err := strconv.ParseInt(contentLength, 10, 0)
	if err != nil {
		return nil, trace.BadParameter("failed to parse Content-Length header: %q", contentLength)
	}

	fs := &httpFileSystem{
		reader:   req.HTTPRequest.Body,
		fileName: req.FileName,
		fileSize: fileSize,
	}

	flags := Flags{
		// scp treats it as a list of files to upload
		Target: []string{req.FileName},
	}

	cfg := Config{
		Flags:          flags,
		FileSystem:     fs,
		User:           req.User,
		ProgressWriter: req.Progress,
		RemoteLocation: req.RemoteLocation,
		AuditLog:       req.AuditLog,
	}

	cmd, err := CreateUploadCommand(cfg)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	return cmd, nil
}