0

Golang怎样解析转换字符串String为http.Header

giselle created at5 years ago view count: 420
report
回复
0
func ParseHeader(s string) http.Header {
    reader := bufio.NewReader(strings.NewReader(s + "\r\n"))
    tp := textproto.NewReader(reader)

    mimeHeader, err := tp.ReadMIMEHeader()
    if err != nil {
        log.Fatal(err)
    }

    // http.Header and textproto.MIMEHeader are both just a map[string][]string
    httpHeader := http.Header(mimeHeader)
    return httpHeader
}
5 years ago 回复

Recent search keywords