(f *DataFrame)
| 2750 | } |
| 2751 | |
| 2752 | func (rl *clientConnReadLoop) processData(f *DataFrame) error { |
| 2753 | cc := rl.cc |
| 2754 | cs := rl.streamByID(f.StreamID) |
| 2755 | data := f.Data() |
| 2756 | if cs == nil { |
| 2757 | cc.mu.Lock() |
| 2758 | neverSent := cc.nextStreamID |
| 2759 | cc.mu.Unlock() |
| 2760 | if f.StreamID >= neverSent { |
| 2761 | // We never asked for this. |
| 2762 | cc.logf("http2: Transport received unsolicited DATA frame; closing connection") |
| 2763 | return ConnectionError(ErrCodeProtocol) |
| 2764 | } |
| 2765 | // We probably did ask for this, but canceled. Just ignore it. |
| 2766 | // TODO: be stricter here? only silently ignore things which |
| 2767 | // we canceled, but not things which were closed normally |
| 2768 | // by the peer? Tough without accumulating too much state. |
| 2769 | |
| 2770 | // But at least return their flow control: |
| 2771 | if f.Length > 0 { |
| 2772 | cc.mu.Lock() |
| 2773 | ok := cc.inflow.take(f.Length) |
| 2774 | connAdd := cc.inflow.add(int(f.Length)) |
| 2775 | cc.mu.Unlock() |
| 2776 | if !ok { |
| 2777 | return ConnectionError(ErrCodeFlowControl) |
| 2778 | } |
| 2779 | if connAdd > 0 { |
| 2780 | cc.wmu.Lock() |
| 2781 | cc.fr.WriteWindowUpdate(0, uint32(connAdd)) |
| 2782 | cc.bw.Flush() |
| 2783 | cc.wmu.Unlock() |
| 2784 | } |
| 2785 | } |
| 2786 | return nil |
| 2787 | } |
| 2788 | if cs.readClosed { |
| 2789 | cc.logf("protocol error: received DATA after END_STREAM") |
| 2790 | rl.endStreamError(cs, StreamError{ |
| 2791 | StreamID: f.StreamID, |
| 2792 | Code: ErrCodeProtocol, |
| 2793 | }) |
| 2794 | return nil |
| 2795 | } |
| 2796 | if !cs.pastHeaders { |
| 2797 | cc.logf("protocol error: received DATA before a HEADERS frame") |
| 2798 | rl.endStreamError(cs, StreamError{ |
| 2799 | StreamID: f.StreamID, |
| 2800 | Code: ErrCodeProtocol, |
| 2801 | }) |
| 2802 | return nil |
| 2803 | } |
| 2804 | if f.Length > 0 { |
| 2805 | if cs.isHead && len(data) > 0 { |
| 2806 | cc.logf("protocol error: received DATA on a HEAD request") |
| 2807 | rl.endStreamError(cs, StreamError{ |
| 2808 | StreamID: f.StreamID, |
| 2809 | Code: ErrCodeProtocol, |
no test coverage detected