// SendRequest marshalls a HTTP request to the wire.
973421
func (c *client) WriteRequest(req *Request) error {
	if err := c.WriteRequestLine(req.Method, req.Path, req.Query, req.Version.String()); err != nil {
		return err
	}
	for _, h := range req.Headers {
		if err := c.WriteHeader(h.Key, h.Value); err != nil {
			return err
		}
	}
	l := req.ContentLength()
	if l >= 0 {
		if err := c.WriteHeader("Content-Length", fmt.Sprintf("%d", l)); err != nil {
			return err
		}
	}
	if req.Body == nil {
		// doesn't actually start the body, just sends the terminating \r\n
		return c.StartBody()
	}
	// TODO(dfc) Version should implement comparable so we can say version >= HTTP_1_1
	if req.Version.major == 1 && req.Version.minor == 1 {
		if l < 0 {
			if err := c.WriteHeader("Transfer-Encoding", "chunked"); err != nil {
				return err
			}
			if err := c.StartBody(); err != nil {
				return err
			}
			return c.WriteChunked(req.Body)
		}
	}
	if err := c.StartBody(); err != nil {
		return err
	}
	return c.WriteBody(req.Body)
}
564515
func (c *GorymanClient) sendRecv(m *proto.Msg) (*proto.Msg, error) {
	return c.tcp.SendRecv(m)
}
629628
func (c *ResponseClient) SendResponse(req Request, response Response) error {
	raw, err := json.Marshal(response)
	if err != nil {
		return err
	}

	r, err := http.NewRequest("PUT", req.ResponseURL, bytes.NewReader(raw))
	if err != nil {
		return err
	}

	resp, err := c.client.Do(r)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)

	if code := resp.StatusCode; code/100 != 2 {
		return fmt.Errorf("unexpected response from pre-signed url: %v: %v", code, string(body))
	}

	return nil
}
1259598
func (p *pullMediatorImpl) SendReq(dest string, items []string, nonce uint64) {
	req := &proto.GossipMessage{
		Channel: p.config.Channel,
		Tag:     p.config.Tag,
		Nonce:   0,
		Content: &proto.GossipMessage_DataReq{
			DataReq: &proto.DataRequest{
				MsgType: p.config.MsgType,
				Nonce:   nonce,
				Digests: util.StringsToBytes(items),
			},
		},
	}
	if p.logger.IsEnabledFor(zapcore.DebugLevel) {
		p.logger.Debug("Sending", req.GetDataReq().FormattedDigests(), "to", dest)
	}
	sMsg, err := req.NoopSign()
	if err != nil {
		p.logger.Warningf("Failed creating SignedGossipMessage: %+v", errors.WithStack(err))
		return
	}
	p.Sndr.Send(sMsg, p.peersWithEndpoints(dest)...)
}
546506
func (r *Response) Send() (int, error) {
	r.mu.Lock()
	defer r.mu.Unlock()

	if r.sent {
		return 0, errSentAlready
	}
	r.sent = true

	if r.code == 0 {
		r.code = 200
	}
	status := getStatus(r.code)

	r.WriteHeader(r.code)
	r.Field(fieldStatus, status)

	if _, hasMsg := r.fields[fieldMsg]; !hasMsg && status == StatusError {
		r.Message(http.StatusText(r.code))
	}

	if _, hasData := r.fields[fieldData]; !hasData && status != StatusError {
		r.Data([]byte(nil))
	}

	j, err := json.Marshal(r.fields)

	if err != nil {
		return 0, err
	}

	return r.Write(j)
}
1151097
func (c client) Send(name string, reqValue wire.Value) (wire.Value, error) {
	reqEnvelope := wire.Envelope{
		Name:  name,
		Type:  wire.Call,
		SeqID: 1, // don't care
		Value: reqValue,
	}

	// TODO(abg): We don't use or support out-of-order requests and responses
	// for plugin communaction so this should be fine for now but we may
	// eventually want to match responses to requests using seqID.

	var buff bytes.Buffer
	if err := c.p.EncodeEnveloped(reqEnvelope, &buff); err != nil {
		return wire.Value{}, err
	}

	resBody, err := c.t.Send(buff.Bytes())
	if err != nil {
		return wire.Value{}, err
	}

	resEnvelope, err := c.p.DecodeEnveloped(bytes.NewReader(resBody))
	if err != nil {
		return wire.Value{}, err
	}

	switch resEnvelope.Type {
	case wire.Exception:
		var exc exception.TApplicationException
		if err := exc.FromWire(resEnvelope.Value); err != nil {
			return wire.Value{}, err
		}
		return wire.Value{}, &exc

	case wire.Reply:
		return resEnvelope.Value, nil

	default:
		return wire.Value{}, errUnknownEnvelopeType(resEnvelope.Type)
	}
}
1159000
func (c *HTTPClient) Send(req *http.Request) HTTPClientInterface {
	c.request = req
	return c
}
250452
func (d *DockerMonitor) sendRequestToQueue(r *events.Message) {

	key0 := uint64(256203161)
	key1 := uint64(982451653)

	key := d.getHashKey(r)
	h := siphash.Hash(key0, key1, []byte(key))

	d.eventnotifications[int(h%uint64(d.numberOfQueues))] <- r
}
1028201
func (f SenderFunc) Send(ctx context.Context, r Request) (mesos.Response, error) {
	return f(ctx, r)
}
951892
func (c *Client) Send(req *Request, res Response) error {
	// TODO: handle retry, timeouts, etc.
	return c.send(req, res)
}
1093927
func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) {
	ctx, _ = tag.New(ctx, metrics.UpsertMessageType(pmes))

	ms, err := dht.messageSenderForPeer(ctx, p)
	if err != nil {
		stats.Record(ctx, metrics.SentRequestErrors.M(1))
		return nil, err
	}

	start := time.Now()

	rpmes, err := ms.SendRequest(ctx, pmes)
	if err != nil {
		stats.Record(ctx, metrics.SentRequestErrors.M(1))
		return nil, err
	}

	// update the peer (on valid msgs only)
	dht.updateFromMessage(ctx, p, rpmes)

	stats.Record(
		ctx,
		metrics.SentRequests.M(1),
		metrics.SentBytes.M(int64(pmes.Size())),
		metrics.OutboundRequestLatency.M(
			float64(time.Since(start))/float64(time.Millisecond),
		),
	)
	dht.peerstore.RecordLatency(p, time.Since(start))
	logger.Event(ctx, "dhtReceivedMessage", dht.self, p, rpmes)
	return rpmes, nil
}
291232
func (s *Sender) Send(req *http.Request) (resp *http.Response, err error) {
	return s.ExecWithRetry(fmt.Sprintf("%s request to %s", req.Method, req.URL), func() (*http.Response, error) { return s.client.Do(req) })
}
451741
func (r *Request) Send() error {
	err := r.Build()
	if err != nil {
		return err
	}

	err = r.Sign()
	if err != nil {
		return err
	}

	err = r.Do()
	if err != nil {
		return err
	}

	return nil
}
278678
func (s *RegionRequestSender) SendReq(bo *Backoffer, req *tikvrpc.Request, regionID RegionVerID, timeout time.Duration) (*tikvrpc.Response, error) {
	resp, _, err := s.SendReqCtx(bo, req, regionID, timeout)
	return resp, err
}
1329967
func (c *Client) SendRequest(req *http.Request) (resp *APIResponse, err error) {
	u := req.URL.String()
	if !strings.HasPrefix(u, "http") {
		u = fmt.Sprintf("https://%v%v", c.Host, u)
		req.URL, err = url.Parse(u)
		if err != nil {
			return
		}
	}
	if c.User != nil {
		c.OAuth.Sign(req, c.User)
	} else {
		if err = c.Sign(req); err != nil {
			return
		}
	}
	var r *http.Response
	r, err = c.HttpClient.Do(req)
	resp = (*APIResponse)(r)
	return
}
1207763
func (prod *HTTPRequest) sendReq(msg *core.Message) {
	var (
		req *http.Request
		err error
	)

	requestData := bytes.NewBuffer(msg.GetPayload())

	if prod.rawPackets {
		// Assume the message already contains an HTTP request in wire format.
		// Create a Request object, override host, port and scheme, and send it out.
		req, err = http.ReadRequest(bufio.NewReader(requestData))
		if req != nil {
			req.URL.Host = prod.destinationURL.Host
			req.URL.Scheme = prod.destinationURL.Scheme
			req.RequestURI = ""
		}
	} else {
		// Encapsulate the message in a POST request
		req, err = http.NewRequest("POST", prod.destinationURL.String(), requestData)
		if req != nil {
			req.Header.Add("Content-type", prod.encoding)
		}
	}

	if err != nil {
		prod.Logger.Error("Invalid request: ", err)
		prod.TryFallback(msg)
		prod.lastError = err
		return // ### return, malformed request ###
	}

	go func() {
		_, _, err := httpRequestWrapper(http.DefaultClient.Do(req))
		prod.lastError = err
		if err != nil {
			// Fail
			prod.Logger.WithError(err).Error("Send failed")
			if !prod.isHostUp() {
				prod.Logger.Error("Host is down")
			}
			prod.TryFallback(msg)
			return
		}
		// Success
		// TBD: health check? (ex-fuse breaker)
	}()
}
1370432
func (r *Request) Send() error {
	// Always run Complete handlers
	defer func() {
		r.Handlers.Complete.Run(r)
	}()

	// Build and Sign the request.
	r.Build()
	if r.Error != nil {
		return r.Error
	}

	// Send the request. r.HTTPResponse should be populated after these handlers run.
	r.Handlers.Send.Run(r)
	if r.Error != nil {
		return r.Error
	}

	// Validate the response. This is a good place to create a r.Error if
	// the response is not a 2xx status code.
	r.Handlers.ValidateResponse.Run(r)
	if r.Error != nil {
		// Run DecodeError handlers. This is a good place to add custom error response
		// parsing.
		r.Handlers.DecodeError.Run(r)
		return r.Error
	}

	// Decode the response. Commonly will populate r.Data variable with a parsed response body.
	r.Handlers.Decode.Run(r)
	return r.Error
}