func writeHeader(w xo.Writer, fields Fields) error { for _, f := range fields { buf, err := w.Reserve(len(f.Name) + len(f.Value) + 4) if err != nil { return err } n := copy(buf[0:], f.Name) n += copy(buf[n:], ": ") n += copy(buf[n:], f.Value) n += copy(buf[n:], "\r\n") if err := w.Commit(n); err != nil { return err } } _, err := w.Write(crlf) return err }
// WriteRequestHeader writes an HTTP request header to w. func WriteRequestHeader(w xo.Writer, req *Request) error { buf, err := w.Reserve(len(req.Method) + len(req.URI) + 10 + 20 + 20) if err != nil { return err } n := copy(buf[0:], req.Method) n += copy(buf[n:], " ") n += copy(buf[n:], req.URI) n += copy(buf[n:], " HTTP/") n += itoa(buf[n:], int64(req.Major)) n += copy(buf[n:], ".") n += itoa(buf[n:], int64(req.Minor)) n += copy(buf[n:], "\r\n") if err := w.Commit(n); err != nil { return err } return writeHeader(w, req.Fields) }