func (req *Request) Write(w *bufio.Writer) error {
	if len(req.Header.Host()) == 0 || req.parsedURI {
		uri := req.URI()
		host := uri.Host()
		if len(host) == 0 {
			return errRequestHostRequired
		}
		req.Header.SetHostBytes(host)
		req.Header.SetRequestURIBytes(uri.RequestURI())
	}

	if req.bodyStream != nil {
		return req.writeBodyStream(w)
	}

	body := req.bodyBytes()
	var err error
	if req.onlyMultipartForm() {
		body, err = marshalMultipartForm(req.multipartForm, req.multipartFormBoundary)
		if err != nil {
			return fmt.Errorf("error when marshaling multipart form: %s", err)
		}
		req.Header.SetMultipartFormBoundary(req.multipartFormBoundary)
	}

	hasBody := !req.Header.ignoreBody()
	if hasBody {
		if len(body) == 0 {
			body = req.postArgs.QueryString()
		}
		req.Header.SetContentLength(len(body))
	}
	if err = req.Header.Write(w); err != nil {
		return err
	}
	if hasBody {
		_, err = w.Write(body)
	} else if len(body) > 0 {
		return fmt.Errorf("non-zero body for non-POST request. body=%q", body)
	}
	return err
}
func (req *Request) Write(w *bufio.Writer) error {
	if len(req.Header.Host()) == 0 || req.parsedURI {
		uri := req.URI()
		host := uri.Host()
		if len(host) == 0 {
			return errRequestHostRequired
		}
		req.Header.SetHostBytes(host)
		req.Header.SetRequestURIBytes(uri.RequestURI())
	}

	if req.bodyStream != nil {
		return req.writeBodyStream(w)
	}

	body := req.bodyBytes()
	var err error
	if req.onlyMultipartForm() {
		body, err = marshalMultipartForm(req.multipartForm, req.multipartFormBoundary)
		if err != nil {
			return fmt.Errorf("error when marshaling multipart form: %s", err)
		}
		req.Header.SetMultipartFormBoundary(req.multipartFormBoundary)
	}

	hasBody := !req.Header.ignoreBody()
	if hasBody {
		if len(body) == 0 {
			body = req.postArgs.QueryString()
		}
		req.Header.SetContentLength(len(body))
	}
	if err = req.Header.Write(w); err != nil {
		return err
	}
	if hasBody {
		_, err = w.Write(body)
	} else if len(body) > 0 {
		return fmt.Errorf("non-zero body for non-POST request. body=%q", body)
	}
	return err
}
func ( req * Request ) Write ( w * bufio . Writer ) error { if len ( req . Header . Host ( ) ) == 0 || req . parsedURI { uri := req . URI ( ) host := uri . Host ( ) if len ( host ) == 0 { return errRequestHostRequired } req . Header . SetHostBytes ( host ) req . Header . SetRequestURIBytes ( uri . RequestURI ( ) ) } if req . bodyStream != nil { return req . writeBodyStream ( w ) } body := req . bodyBytes ( ) var err error if req . onlyMultipartForm ( ) { body , err = marshalMultipartForm ( req . multipartForm , req . multipartFormBoundary ) if err != nil { return fmt . Errorf ( " " , err ) } req . Header . SetMultipartFormBoundary ( req . multipartFormBoundary ) } hasBody := ! req . Header . ignoreBody ( ) if hasBody { if len ( body ) == 0 { body = req . postArgs . QueryString ( ) } req . Header . SetContentLength ( len ( body ) ) } if err = req . Header . Write ( w ) ; err != nil { return err } if hasBody { _ , err = w . Write ( body ) } else if len ( body ) > 0 { return fmt . Errorf ( " " , body ) } return err }
// Write writes request to w.
//
// Write doesn't flush request to w for performance reasons.
//
// See also WriteTo.
Write writes request to w . Write doesn t flush request to w for performance reasons . See also WriteTo .