fix crash on header callback

merge_conn
fangdingjun 6 years ago
parent 98a084fa18
commit 2549e70d74

@ -183,6 +183,12 @@ func onHeaderCallback(ptr unsafe.Pointer, streamID C.int,
//log.Println("onHeaderCallback end") //log.Println("onHeaderCallback end")
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
} }
var header http.Header
if conn.isServer {
header = s.request.Header
} else {
header = s.response.Header
}
goname = strings.ToLower(goname) goname = strings.ToLower(goname)
switch goname { switch goname {
case ":method": case ":method":
@ -206,16 +212,24 @@ func onHeaderCallback(ptr unsafe.Pointer, streamID C.int,
s.response.StatusCode = statusCode s.response.StatusCode = statusCode
s.response.Status = http.StatusText(statusCode) s.response.Status = http.StatusText(statusCode)
case "content-length": case "content-length":
s.response.Header.Add(goname, govalue) header.Add(goname, govalue)
n, err := strconv.ParseInt(govalue, 10, 64) n, err := strconv.ParseInt(govalue, 10, 64)
if err == nil { if err == nil {
if conn.isServer {
s.request.ContentLength = n
} else {
s.response.ContentLength = n s.response.ContentLength = n
} }
}
case "transfer-encoding": case "transfer-encoding":
s.response.Header.Add(goname, govalue) header.Add(goname, govalue)
if conn.isServer {
s.request.TransferEncoding = append(s.response.TransferEncoding, govalue)
} else {
s.response.TransferEncoding = append(s.response.TransferEncoding, govalue) s.response.TransferEncoding = append(s.response.TransferEncoding, govalue)
}
default: default:
s.response.Header.Add(goname, govalue) header.Add(goname, govalue)
} }
//log.Println("onHeaderCallback end") //log.Println("onHeaderCallback end")
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR

Loading…
Cancel
Save