transport: don't check s.header on the server side in Stream.Header (#3063)

Previously this would fall into returning the same "s.header.Copy(), nil"
condition at the end of the function, returning an empty MD.  After a recent
change it would instead check headerValid, which is always false on servers,
and return nil and an error.  Callers were ignoring this error so no behavior
change was seen, but there is no need to check s.headers here.
This commit is contained in:
Doug Fawley
2019-10-02 10:00:00 -07:00
committed by GitHub
parent 5df282efcf
commit 2e14ef2723
2 changed files with 5 additions and 4 deletions

View File

@ -751,7 +751,7 @@ func (t *http2Server) checkForHeaderListSize(it interface{}) bool {
return true
}
// WriteHeader sends the header metedata md back to the client.
// WriteHeader sends the header metadata md back to the client.
func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error {
if s.updateHeaderSent() || s.getState() == streamDone {
return ErrIllegalHeaderWrite

View File

@ -254,7 +254,7 @@ type Stream struct {
headerChanClosed uint32 // set when headerChan is closed. Used to avoid closing headerChan multiple times.
// headerValid indicates whether a valid header was received. Only
// meaningful after headerChan is closed (always call waitOnHeader() before
// reading its value).
// reading its value). Not valid on server side.
headerValid bool
// hdrMu protects header and trailer metadata on the server-side.
@ -351,9 +351,10 @@ func (s *Stream) Done() <-chan struct{} {
// available. It blocks until i) the metadata is ready or ii) there is no header
// metadata or iii) the stream is canceled/expired.
//
// On server side, it returns the out header after t.WriteHeader is called.
// On server side, it returns the out header after t.WriteHeader is called. It
// does not block and must not be called until after WriteHeader.
func (s *Stream) Header() (metadata.MD, error) {
if s.headerChan == nil && s.header != nil {
if s.headerChan == nil {
// On server side, return the header in stream. It will be the out
// header after t.WriteHeader is called.
return s.header.Copy(), nil