attach content-type to trailer if the trailer is the only response.
This commit is contained in:
@ -456,17 +456,24 @@ func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error {
|
|||||||
// TODO(zhaoq): Now it indicates the end of entire stream. Revisit if early
|
// TODO(zhaoq): Now it indicates the end of entire stream. Revisit if early
|
||||||
// OK is adopted.
|
// OK is adopted.
|
||||||
func (t *http2Server) WriteStatus(s *Stream, statusCode codes.Code, statusDesc string) error {
|
func (t *http2Server) WriteStatus(s *Stream, statusCode codes.Code, statusDesc string) error {
|
||||||
s.mu.RLock()
|
var headersSent bool
|
||||||
|
s.mu.Lock()
|
||||||
if s.state == streamDone {
|
if s.state == streamDone {
|
||||||
s.mu.RUnlock()
|
s.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.mu.RUnlock()
|
if s.headerOk {
|
||||||
|
headersSent = true
|
||||||
|
}
|
||||||
|
s.mu.Unlock()
|
||||||
if _, err := wait(s.ctx, t.shutdownChan, t.writableChan); err != nil {
|
if _, err := wait(s.ctx, t.shutdownChan, t.writableChan); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.hBuf.Reset()
|
t.hBuf.Reset()
|
||||||
|
if !headersSent {
|
||||||
t.hEnc.WriteField(hpack.HeaderField{Name: ":status", Value: "200"})
|
t.hEnc.WriteField(hpack.HeaderField{Name: ":status", Value: "200"})
|
||||||
|
t.hEnc.WriteField(hpack.HeaderField{Name: "content-type", Value: "application/grpc"})
|
||||||
|
}
|
||||||
t.hEnc.WriteField(
|
t.hEnc.WriteField(
|
||||||
hpack.HeaderField{
|
hpack.HeaderField{
|
||||||
Name: "grpc-status",
|
Name: "grpc-status",
|
||||||
|
Reference in New Issue
Block a user