// newHTTP returns a http struct
322454
func newHTTP(r *http.Request) *awsxray.HTTP {
	scheme := "http"
	host := r.Host

	if len(r.URL.Scheme) > 0 {
		scheme = r.URL.Scheme
	}

	if len(r.URL.Host) > 0 {
		host = r.URL.Host
	}

	return &awsxray.HTTP{
		Request: &awsxray.Request{
			Method:    r.Method,
			URL:       fmt.Sprintf("%s://%s%s", scheme, host, r.URL.Path),
			ClientIP:  getIp(r),
			UserAgent: r.UserAgent(),
		},
		Response: &awsxray.Response{
			Status: 200,
		},
	}
}
421632
func NewHTTPTransport(url string, options ...HTTPOption) (*HTTPTransport, error) {
	c := &HTTPTransport{
		logger:    log.NullLogger,
		url:       url,
		client:    &http.Client{Timeout: defaultHTTPTimeout},
		batchSize: 100,
		batch:     []*zipkincore.Span{},
	}

	for _, option := range options {
		option(c)
	}
	return c, nil
}
905386
func New(httpClient *http.Client, config Config) (*Client, error) {
	c := NewClient(httpClient)
	c.Config = config

	baseURL, err := url.Parse("https://" + config.Host)

	if err != nil {
		return nil, err
	}

	c.BaseURL = baseURL
	return c, nil
}
214208
func NewHTTPServer(cors []string, vhosts []string, timeouts HTTPTimeouts, srv http.Handler) *http.Server {
	// Wrap the CORS-handler within a host-handler
	handler := newCorsHandler(srv, cors)
	handler = newVHostHandler(vhosts, handler)

	// Make sure timeout values are meaningful
	if timeouts.ReadTimeout < time.Second {
		log.Warn("Sanitizing invalid HTTP read timeout", "provided", timeouts.ReadTimeout, "updated", DefaultHTTPTimeouts.ReadTimeout)
		timeouts.ReadTimeout = DefaultHTTPTimeouts.ReadTimeout
	}
	if timeouts.WriteTimeout < time.Second {
		log.Warn("Sanitizing invalid HTTP write timeout", "provided", timeouts.WriteTimeout, "updated", DefaultHTTPTimeouts.WriteTimeout)
		timeouts.WriteTimeout = DefaultHTTPTimeouts.WriteTimeout
	}
	if timeouts.IdleTimeout < time.Second {
		log.Warn("Sanitizing invalid HTTP idle timeout", "provided", timeouts.IdleTimeout, "updated", DefaultHTTPTimeouts.IdleTimeout)
		timeouts.IdleTimeout = DefaultHTTPTimeouts.IdleTimeout
	}
	// Bundle and start the HTTP server
	return &http.Server{
		Handler:      handler,
		ReadTimeout:  timeouts.ReadTimeout,
		WriteTimeout: timeouts.WriteTimeout,
		IdleTimeout:  timeouts.IdleTimeout,
	}
}
1356394
func (client Client) newHTTPRequest(passedRequest requestOptions) (*cloudcontroller.Request, error) {
	var request *http.Request
	var err error
	if passedRequest.URI != "" {
		var (
			path *url.URL
			base *url.URL
		)

		path, err = url.Parse(passedRequest.URI)
		if err != nil {
			return nil, err
		}

		base, err = url.Parse(client.API())
		if err != nil {
			return nil, err
		}

		request, err = http.NewRequest(
			passedRequest.Method,
			base.ResolveReference(path).String(),
			passedRequest.Body,
		)
	} else {
		request, err = client.router.CreateRequest(
			passedRequest.RequestName,
			map[string]string(passedRequest.URIParams),
			passedRequest.Body,
		)
		if err == nil {
			request.URL.RawQuery = passedRequest.Query.Encode()
		}
	}
	if err != nil {
		return nil, err
	}

	request.Header = http.Header{}
	request.Header.Set("Accept", "application/json")
	request.Header.Set("User-Agent", client.userAgent)

	if passedRequest.Body != nil {
		request.Header.Set("Content-Type", "application/json")
	}

	// Make sure the body is the same as the one in the request
	return cloudcontroller.NewRequest(request, passedRequest.Body), nil
}
79993
func (c *Client) NewRequest(urlStr string) (req *Request, err error) {
	req, err = newRequest(c, urlStr)
	if err != nil {
		return
	}

	c.applyRequestHeaders(req)

	return
}
1079765
func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error) {
	rel, err := url.Parse(urlStr)
	if err != nil {
		return nil, err
	}

	u := c.BaseURL.ResolveReference(rel)

	var buf io.ReadWriter
	if body != nil {
		buf = new(bytes.Buffer)
		err := json.NewEncoder(buf).Encode(body)
		if err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest(method, u.String(), buf)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	authHeader := "Bearer " + c.Option.APIKey

	req.Header.Set("Authorization", authHeader)
	if c.UserAgent != "" {
		req.Header.Add("User-Agent", c.UserAgent)
	}

	return req, nil
}
872583
func (r *request) toHTTP() (*http.Request, error) {
	// Encode the query parameters
	r.url.RawQuery = r.params.Encode()

	// Get the url sring
	urlRaw := r.url.String()

	// Check if we should encode the body
	if r.body == nil && r.obj != nil {
		if b, err := encodeBody(r.obj); err != nil {
			return nil, err
		} else {
			r.body = b
		}
	}

	// Create the HTTP request
	req, err := http.NewRequest(r.method, urlRaw, r.body)

	// Setup auth
	if err == nil && r.config.HttpAuth != nil {
		req.SetBasicAuth(r.config.HttpAuth.Username, r.config.HttpAuth.Password)
	}

	return req, err
}
844518
func NewRequest() *Request {
	return &Request{
		Counter:    1,
		URLStruct:  &url.URL{},
		Header:     make(http.Header),
		PathParams: make(map[string]string),
	}
}
438781
func (c *Client) NewRequest(method, urlStr string, opt interface{}, body interface{}) (*http.Request, error) {
	rel, err := addOptions(urlStr, opt)
	if err != nil {
		return nil, err
	}

	if AuthTest {
		// Add the auth_test param
		values := rel.Query()
		values.Add("auth_test", strconv.FormatBool(AuthTest))
		rel.RawQuery = values.Encode()
	}

	u := c.BaseURL.ResolveReference(rel)

	buf := new(bytes.Buffer)
	if body != nil {
		err := json.NewEncoder(buf).Encode(body)
		if err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest(method, u.String(), buf)
	if err != nil {
		return nil, err
	}

	req.Header.Add("Authorization", "Bearer "+c.authToken)
	req.Header.Add("Content-Type", "application/json")
	return req, nil
}
10583
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	iw := newResponseWriter(w)

	createRequestContext(r)
	defer deleteRequestContext(r)

	s.serveHTTP(iw, r)
}
1231231
func NewHTTPClient(timeout time.Duration, threshold int64, client *http.Client) *HTTPClient {
	breaker := NewThresholdBreaker(threshold)
	return NewHTTPClientWithBreaker(breaker, timeout, client)
}
677557
func CreateHTTP(addr string, handle http.Handler) (*http.Server, net.Listener, error) {
	l, err := net.Listen("tcp", addr)

	if err != nil {
		return nil, nil, err
	}

	return MakeBaseServer(l, handle, nil)
}
335660
func (r *request) toHTTP() (*http.Request, error) {
	// Encode the query parameters
	r.url.RawQuery = r.params.Encode()

	// Check if we should encode the body
	if r.body == nil && r.obj != nil {
		if b, err := encodeBody(r.obj); err != nil {
			return nil, err
		} else {
			r.body = b
		}
	}

	// Create the HTTP request
	req, err := http.NewRequest(r.method, r.url.RequestURI(), r.body)
	if err != nil {
		return nil, err
	}

	// Optionally configure HTTP basic authentication
	if r.url.User != nil {
		username := r.url.User.Username()
		password, _ := r.url.User.Password()
		req.SetBasicAuth(username, password)
	} else if r.config.HttpAuth != nil {
		req.SetBasicAuth(r.config.HttpAuth.Username, r.config.HttpAuth.Password)
	}

	req.Header.Add("Accept-Encoding", "gzip")
	if r.token != "" {
		req.Header.Set("X-Nomad-Token", r.token)
	}

	req.URL.Host = r.url.Host
	req.URL.Scheme = r.url.Scheme
	req.Host = r.url.Host
	return req, nil
}
341377
func NewHTTPClient(opts Options) (*HTTPClient, error) {
	o := *(*options)(opts.applyDefaults())
	return &HTTPClient{
		options: o,
		hc:      o.HTTPClient,
	}, nil
}
5420
func (c *Client) NewRequest(ctx context.Context, method, path string, params interface{}, data interface{}) *request.Request {
	httpReq, _ := http.NewRequest(method, path, nil)
	httpReq = httpReq.WithContext(ctx)
	httpReq.URL, _ = url.Parse(c.Info.Endpoint + path)

	r := request.New(httpReq, c.Info, c.Handlers.Copy(), params, data)
	r.HTTPClient = c.HTTPClient
	return r
}
873527
func (c *Client) newRequest(method Method, endpoint string) *Request {
	req := &Request{
		Method:  method,
		URL:     resourceURL(c.BaseURL(), endpoint),
		Headers: http.Header(make(map[string][]string)),
	}

	// Copy over the headers. Don't set them directly to ensure changing
	// them on the request doesn't change them on the client.
	for k, vv := range c.Headers {
		for _, v := range vv {
			req.Headers.Add(k, v)
		}
	}

	return req
}