github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/httptransport/transformer/util_header.go (about)

     1  package transformer
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  	"net/textproto"
     7  
     8  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
     9  )
    10  
    11  func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader {
    12  	header := textproto.MIMEHeader{}
    13  	for _, h := range headers {
    14  		for k, values := range h {
    15  			for _, v := range values {
    16  				header.Add(k, v)
    17  			}
    18  		}
    19  	}
    20  	return header
    21  }
    22  
    23  type HeaderWriter interface {
    24  	httpx.WithHeader
    25  	io.Writer
    26  }
    27  
    28  func WriterWithHeader(w io.Writer, header http.Header) HeaderWriter {
    29  	return &headerWriter{Writer: w, header: header}
    30  }
    31  
    32  func (f *headerWriter) Header() http.Header { return f.header }
    33  
    34  type headerWriter struct {
    35  	io.Writer
    36  	header http.Header
    37  }