// NewRequest is used to create a new request
505196
func (c *Client) NewRequest(method, path string) *request {
	r := &request{
		method: method,
		url:    c.config.BOSHAddress + path,
		params: make(map[string][]string),
		header: make(map[string]string),
	}
	return r
}
1015227
func (mock *HTTPMock) NewRequest(method, url string, body io.Reader) (*http.Response, error) {
	req, err := http.NewRequest(method, url, body)
	if err != nil {
		return nil, err
	}

	recorder := httptest.NewRecorder()
	mock.handler.ServeHTTP(recorder, req)
	return recorder.Result(), nil
}
216713
func NewRequest(conn Conn, data []byte, offset int) Request {
	return &request{conn: conn, data: data, offset: offset}
}
62363
func NewRequest(t Type, body io.WriterTo) *Request {
	req := &Request{
		Body:       &copyReader{WriterTo: body},
		Proto:      "OFP/1.3",
		ProtoMajor: 1, ProtoMinor: 3,
	}

	req.Header.Version = uint8(req.ProtoMajor + req.ProtoMinor)
	req.Header.Type = t

	return req
}
507933
func NewRequest(a *assert.Assertion, client *http.Client, method, path string) *Request {
	if client == nil {
		client = http.DefaultClient
	}

	return &Request{
		assertion: a,
		client:    client,
		method:    method,
		path:      path,
	}
}
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
}
235311
func newRequest(server, method string, URI string, body io.Reader) (*http.Request, error) {
	URL := fmt.Sprintf("%s%s", server, URI)
	req, err := http.NewRequest(method, URL, body)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-Type", "application/json")

	return req, nil
}
1083213
func NewRequest(q string) *Request {
	req := &Request{
		q:      q,
		Header: make(map[string][]string),
	}
	return req
}
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
}
975911
func (client *Client) newRequest(passedRequest requestOptions) (*http.Request, error) {
	var request *http.Request
	var err error

	if passedRequest.URL != "" {
		request, err = http.NewRequest(
			passedRequest.Method,
			passedRequest.URL,
			passedRequest.Body,
		)
	} else {
		request, err = client.router.CreateRequest(
			passedRequest.RequestName,
			passedRequest.URIParams,
			passedRequest.Body,
		)
	}
	if err != nil {
		return nil, err
	}

	if passedRequest.Query != nil {
		request.URL.RawQuery = passedRequest.Query.Encode()
	}

	if passedRequest.Header != nil {
		request.Header = passedRequest.Header
	} else {
		request.Header = http.Header{}
	}
	request.Header.Set("Accept", "application/json")
	request.Header.Set("Connection", "close")
	request.Header.Set("User-Agent", client.userAgent)

	return request, nil
}
923524
func NewRequest(i *http.Request, f *Fibre) *Request {
	return &Request{i, f, time.Now()}
}
449186
func (c *depClient) 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)
	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("User-Agent", userAgent)
	req.Header.Add("Content-Type", mediaType)
	req.Header.Add("Accept", mediaType)
	req.Header.Add("X-Server-Protocol-Version", "2")
	return req, nil
}
405245
func (c *Client) NewRequest(s string) (*http.Request, error) {
	rel, err := url.Parse(c.BasePath + s)
	if err != nil {
		return nil, err
	}

	q := rel.Query()
	q.Set("api_key", c.APIKey)
	q.Set("rating", c.Rating)
	rel.RawQuery = q.Encode()

	u := c.BaseURL.ResolveReference(rel)

	if EnvBool("GIPHY_VERBOSE", false) {
		fmt.Println("giphy: GET", u.String())
	}

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

	req.Header.Add("User-Agent", c.UserAgent)
	return req, nil
}
644376
func (c *Client) NewRequest(method, urlStr string, body interface{}, apiVersion string) (req *APIRequest, err error) {
	var rel *url.URL
	var buf io.ReadWriter
	req = &APIRequest{}

	// I'm not sure how to get this method to return an error intentionally for testing. For testing purposes, I've
	// added a switch so that the error handling in dependent methods can be tested.
	if os.Getenv("GOCD_RAISE_ERROR_NEW_REQUEST") == "yes" {
		return req, errors.New("Mock Testing Error")
	}

	// Some calls
	if strings.HasPrefix(urlStr, "/") {
		urlStr = urlStr[1:]
	} else {
		urlStr = "api/" + urlStr
	}
	if rel, err = url.Parse(urlStr); err != nil {
		return req, err
	}

	u := c.params.BuildPath(rel)

	if body != nil {
		buf = new(bytes.Buffer)

		enc := json.NewEncoder(buf)
		enc.SetIndent("", "  ")
		err := enc.Encode(body)

		if err != nil {
			return nil, err
		}
		bdy, _ := ioutil.ReadAll(buf)
		req.Body = string(bdy)

		buf = new(bytes.Buffer)
		enc = json.NewEncoder(buf)
		enc.SetIndent("", "  ")
		enc.Encode(body)
	}

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

	if body != nil {
		req.HTTP.Header.Set("Content-Type", "application/json")
	}
	if apiVersion != "" {
		req.HTTP.Header.Set("Accept", apiVersion)
	}
	req.HTTP.Header.Set("User-Agent", c.params.UserAgent)

	if c.cookie == "" {
		if c.params.Username != "" && c.params.Password != "" {
			req.HTTP.SetBasicAuth(c.params.Username, c.params.Password)
		}
	} else {
		req.HTTP.Header.Set("Cookie", c.cookie)
	}

	return
}
995841
func NewRequest(username, password string) Request {
	invalidCh := make(chan InvalidPassword)
	createdCh := make(chan CreatedUser)
	authenticatedCh := make(chan AuthenticatedUser)

	return Request{
		Time:     filu.Now(),
		Username: username,
		Password: password,

		InvalidPassword:   invalidCh,
		CreatedUser:       createdCh,
		AuthenticatedUser: authenticatedCh,

		sendInvalidPassword:   invalidCh,
		sendCreatedUser:       createdCh,
		sendAuthenticatedUser: authenticatedCh,
	}
}
617016
func (c *Client) newRequest(method, path string) (*request, error) {
	base, _ := url.Parse(c.config.Address)
	u, err := url.Parse(path)
	if err != nil {
		return nil, err
	}
	r := &request{
		config: &c.config,
		method: method,
		url: &url.URL{
			Scheme: base.Scheme,
			User:   base.User,
			Host:   base.Host,
			Path:   u.Path,
		},
		params: make(map[string][]string),
	}
	if c.config.Region != "" {
		r.params.Set("region", c.config.Region)
	}
	if c.config.Namespace != "" {
		r.params.Set("namespace", c.config.Namespace)
	}
	if c.config.WaitTime != 0 {
		r.params.Set("wait", durToMsec(r.config.WaitTime))
	}
	if c.config.SecretID != "" {
		r.token = r.config.SecretID
	}

	// Add in the query parameters, if any
	for key, values := range u.Query() {
		for _, value := range values {
			r.params.Add(key, value)
		}
	}

	return r, nil
}
303302
func NewRequest(dst, urlStr string) (*Request, error) {
	if dst == "" {
		dst = "."
	}
	req, err := http.NewRequest("GET", urlStr, nil)
	if err != nil {
		return nil, err
	}
	return &Request{
		HTTPRequest: req,
		Filename:    dst,
	}, nil
}