reader verifies the server preface and reads all subsequent data from network connection. If the server preface is not read successfully, an error is pushed to errCh; otherwise errCh is closed with no error.
(errCh chan<- error)
| 1686 | // network connection. If the server preface is not read successfully, an |
| 1687 | // error is pushed to errCh; otherwise errCh is closed with no error. |
| 1688 | func (t *http2Client) reader(errCh chan<- error) { |
| 1689 | var errClose error |
| 1690 | defer func() { |
| 1691 | close(t.readerDone) |
| 1692 | if errClose != nil { |
| 1693 | t.Close(errClose) |
| 1694 | } |
| 1695 | }() |
| 1696 | |
| 1697 | if err := t.readServerPreface(); err != nil { |
| 1698 | errCh <- err |
| 1699 | return |
| 1700 | } |
| 1701 | close(errCh) |
| 1702 | if t.keepaliveEnabled { |
| 1703 | atomic.StoreInt64(&t.lastRead, time.Now().UnixNano()) |
| 1704 | } |
| 1705 | |
| 1706 | // loop to keep reading incoming messages on this transport. |
| 1707 | for { |
| 1708 | t.controlBuf.throttle() |
| 1709 | frame, err := t.framer.readFrame() |
| 1710 | if t.keepaliveEnabled { |
| 1711 | atomic.StoreInt64(&t.lastRead, time.Now().UnixNano()) |
| 1712 | } |
| 1713 | if err != nil { |
| 1714 | // Abort an active stream if the http2.Framer returns a |
| 1715 | // http2.StreamError. This can happen only if the server's response |
| 1716 | // is malformed http2. |
| 1717 | if se, ok := err.(http2.StreamError); ok { |
| 1718 | t.mu.Lock() |
| 1719 | s := t.activeStreams[se.StreamID] |
| 1720 | t.mu.Unlock() |
| 1721 | if s != nil { |
| 1722 | // use error detail to provide better err message |
| 1723 | code := http2ErrConvTab[se.Code] |
| 1724 | errorDetail := t.framer.errorDetail() |
| 1725 | var msg string |
| 1726 | if errorDetail != nil { |
| 1727 | msg = errorDetail.Error() |
| 1728 | } else { |
| 1729 | msg = "received invalid frame" |
| 1730 | } |
| 1731 | t.closeStream(s, status.Error(code, msg), true, http2.ErrCodeProtocol, status.New(code, msg), nil, false) |
| 1732 | } |
| 1733 | continue |
| 1734 | } |
| 1735 | // Transport error. |
| 1736 | errClose = connectionErrorf(true, err, "error reading from server: %v", err) |
| 1737 | return |
| 1738 | } |
| 1739 | switch frame := frame.(type) { |
| 1740 | case *http2.MetaHeadersFrame: |
| 1741 | t.operateHeaders(frame) |
| 1742 | case *parsedDataFrame: |
| 1743 | t.handleData(frame) |
| 1744 | frame.data.Free() |
| 1745 | case *http2.RSTStreamFrame: |
no test coverage detected