// Given an io.Writer which is new to the stream, sends it the header and
// current body data necessary for it to catch up and begin playing a valid
// stream
774169
func (wk *WebmKeeper) Bootstrap(w io.Writer) error {
	if _, err := w.Write(wk.header.Bytes()); err != nil {
		return err
	}
	if _, err := w.Write(wk.body.Bytes()); err != nil {
		return err
	}
	return nil
}
1292569
func (w *responseWriter) Write(p []byte) (int, error) {
	w.started = true
	return w.writer.Write(p)
}
640327
func (self *ErrWrapper) WriteHeader(status int) {
	if (status / 100) > 2 {
		self.err.ErrorDispatch(status, self.ResponseWriter, self.req)
	}
}
145031
func (rww *httpResponseRecorder) WriteHeader(httpCode int) {
	rww.respStatusCode = httpCode
	rww.ResponseWriter.WriteHeader(httpCode)
}
20784
func (r *ResponseData) Write(b []byte) (int, error) {
	if !r.Written() {
		r.WriteHeader(http.StatusOK)
	}
	r.Length += len(b)
	return r.ResponseWriter.Write(b)
}
1102782
func (s *statusCodeWithoutCloseNotify) WriteHeader(status int) {
	s.status = status
	s.ResponseWriter.WriteHeader(status)
}
86788
func (r *Response) Write(buf []byte) (int, error) {
	// Some http Handler will call Write directly.
	if !r.wroteHeader.isTrue() {
		if r.status == 0 {
			r.status = 200
		}
		r.WriteHeader(0)
	}
	return r.rw.Write(buf)
}
435951
func CreateWriter(w io.Writer, header Header) (*Writer, error) {
	header.Set("Content-Type", "multipart/mixed")

	mw, err := message.CreateWriter(w, header.Header)
	if err != nil {
		return nil, err
	}

	return &Writer{mw}, nil
}
181575
func WriteRawHead(c http.ResponseWriter, h *Head) {
	c.WriteHeader(h.Status)
	//copy over the headers
	for k, v := range h.Headers {
		for _, vs := range v {
			c.Header().Add(k, vs)
		}
	}

	//write the Content-Type if not a empty string, we do it down here to preserve
	//the given value incase there was an over-write in the headers provided
	//TODO: decide wether to use .Add() or .Set()

	if h.Content != "" {
		c.Header().Add("Content-Type", h.Content)
	}
}
931095
func (r *FastHttpResponse) WriteStream(name string, contentlen int64, modtime time.Time, reader io.Reader) error {

	// do a simple io.Copy, we do it directly into the writer which may be configured to be a compressed
	// writer
	ius := r.Original.Request.Header.Peek("If-Unmodified-Since")
	if t, err := http.ParseTime(string(ius)); ius != nil && err == nil && !modtime.IsZero() {
		// The Date-Modified header truncates sub-second precision, so
		// use mtime < t+1s instead of mtime <= t to check for unmodified.
		if modtime.Before(t.Add(1 * time.Second)) {
			h := r.Original.Response.Header
			h.Del("Content-Type")
			h.Del("Content-Length")
			if h.Peek("Etag") != nil {
				h.Del("Last-Modified")
			}
			h.SetStatusCode(http.StatusNotModified)
			return nil
		}
	}

	if contentlen != -1 {
		r.Original.Response.Header.Set("Content-Length", strconv.FormatInt(contentlen, 10))
	}
	if _, err := io.Copy(r.Writer, reader); err != nil {
		r.Original.Response.Header.SetStatusCode(http.StatusInternalServerError)
		return err
	} else {
		r.Original.Response.Header.SetStatusCode(http.StatusOK)
	}

	return nil
}
244651
func (g *Generator) writeHeader(w io.Writer) error {
	header := append([]byte("// "), []byte(g.header)...)
	header = append(header, []byte("\n\n")...)

	_, err := w.Write(header)
	return err
}
499731
func (w *ResponseWriter) WriteHeader(statusCode int) {
	w.status = statusCode
	w.ResponseWriter.WriteHeader(statusCode)
}
52242
func CreateWriter(w io.Writer, header Header) (*Writer, error) {
	ww, err := createWriter(w, &header)
	if err != nil {
		return nil, err
	}
	if err := textproto.WriteHeader(w, header.Header); err != nil {
		return nil, err
	}
	return ww, nil
}
1169244
func (r *ResponseData) WriteHeader(status int) {
	go IncrCounter([]string{"goa", "response", strconv.Itoa(status)}, 1.0)
	r.Status = status
	r.ResponseWriter.WriteHeader(status)
}
227795
func (r *ResponseRecorder) WriteHeader(status int) {
	r.status = status
	r.ResponseWriterWrapper.WriteHeader(status)
}
906127
func (s *Stream) Write(b []byte) (n int, err error) {
	var deadline <-chan time.Time
	if d, ok := s.writeDeadline.Load().(time.Time); ok && !d.IsZero() {
		timer := time.NewTimer(time.Until(d))
		defer timer.Stop()
		deadline = timer.C
	}

	select {
	case <-s.die:
		return 0, errors.New(errBrokenPipe)
	default:
	}

	// frame split and transmit
	sent := 0
	frame := newFrame(cmdPSH, s.id)
	bts := b
	for len(bts) > 0 {
		sz := len(bts)
		if sz > s.frameSize {
			sz = s.frameSize
		}
		frame.data = bts[:sz]
		bts = bts[sz:]
		n, err := s.sess.writeFrameInternal(frame, deadline)
		sent += n
		if err != nil {
			return sent, err
		}
	}

	return sent, nil
}
1220893
func (t *http2Server) Write(s *Stream, hdr []byte, data []byte, opts *Options) error {
	if !s.isHeaderSent() { // Headers haven't been written yet.
		if err := t.WriteHeader(s, nil); err != nil {
			if _, ok := err.(ConnectionError); ok {
				return err
			}
			// TODO(mmukhi, dfawley): Make sure this is the right code to return.
			return status.Errorf(codes.Internal, "transport: %v", err)
		}
	} else {
		// Writing headers checks for this condition.
		if s.getState() == streamDone {
			// TODO(mmukhi, dfawley): Should the server write also return io.EOF?
			s.cancel()
			select {
			case <-t.ctx.Done():
				return ErrConnClosing
			default:
			}
			return ContextErr(s.ctx.Err())
		}
	}
	// Add some data to header frame so that we can equally distribute bytes across frames.
	emptyLen := http2MaxFrameLen - len(hdr)
	if emptyLen > len(data) {
		emptyLen = len(data)
	}
	hdr = append(hdr, data[:emptyLen]...)
	data = data[emptyLen:]
	df := &dataFrame{
		streamID: s.id,
		h:        hdr,
		d:        data,
		onEachWrite: func() {
			atomic.StoreUint32(&t.resetPingStrikes, 1)
		},
	}
	if err := s.wq.get(int32(len(hdr) + len(data))); err != nil {
		select {
		case <-t.ctx.Done():
			return ErrConnClosing
		default:
		}
		return ContextErr(s.ctx.Err())
	}
	return t.controlBuf.put(df)
}