func (mv *MessageView) SnapshotRequest(req *http.Request) error {
	buf := new(bytes.Buffer)
	fmt.Fprintf(buf, "%s %s HTTP/%d.%d\r\n", req.Method,
		req.URL, req.ProtoMajor, req.ProtoMinor)
	if req.Host != "" {
		fmt.Fprintf(buf, "Host: %s\r\n", req.Host)
	}
	if tec := len(req.TransferEncoding); tec > 0 {
		mv.chunked = req.TransferEncoding[tec-1] == "chunked"
		fmt.Fprintf(buf, "Transfer-Encoding: %s\r\n", strings.Join(req.TransferEncoding, ", "))
	}
	if !mv.chunked && req.ContentLength >= 0 {
		fmt.Fprintf(buf, "Content-Length: %d\r\n", req.ContentLength)
	}
	mv.compress = req.Header.Get("Content-Encoding")
	req.Header.WriteSubset(buf, map[string]bool{
		"Host":              true,
		"Content-Length":    true,
		"Transfer-Encoding": true,
	})
	fmt.Fprint(buf, "\r\n")
	mv.bodyoffset = int64(buf.Len())
	mv.traileroffset = int64(buf.Len())
	ct := req.Header.Get("Content-Type")
	if mv.skipBody && !mv.matchContentType(ct) || req.Body == nil {
		mv.message = buf.Bytes()
		return nil
	}
	data, err := ioutil.ReadAll(req.Body)
	if err != nil {
		return err
	}
	req.Body.Close()
	if mv.chunked {
		cw := httputil.NewChunkedWriter(buf)
		cw.Write(data)
		cw.Close()
	} else {
		buf.Write(data)
	}
	mv.traileroffset = int64(buf.Len())
	req.Body = ioutil.NopCloser(bytes.NewReader(data))
	if req.Trailer != nil {
		req.Trailer.Write(buf)
	} else if mv.chunked {
		fmt.Fprint(buf, "\r\n")
	}
	mv.message = buf.Bytes()
	return nil
}
SnapshotRequest reads the request into the MessageView. If mv.skipBody is false
it will also read the body into memory and replace the existing body with
the in-memory copy. This method is semantically a no-op.
package messageview
import (
	"bytes"
	"compress/flate"
	"compress/gzip"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httputil"
	"strings"
)
type MessageView struct {
	message       []byte
	cts           []string
	chunked       bool
	skipBody      bool
	compress      string
	bodyoffset    int64
	traileroffset int64
}
type config struct {
	decode bool
}
type Option func(*config)
func Decode() Option {
	return func(c *config) {
		c.decode = true
	}
}
func New() *MessageView {
	return &MessageView{}
}
func (mv *MessageView) SkipBody(skipBody bool) {
	mv.skipBody = skipBody
}
func (mv *MessageView) SkipBodyUnlessContentType(cts ...string) {
	mv.skipBody = true
	mv.cts = cts
}