@@ -1390,7 +1390,7 @@ func (sc *serverConn) processFrame(f Frame) error {
1390
1390
// First frame received must be SETTINGS.
1391
1391
if ! sc .sawFirstSettings {
1392
1392
if _ , ok := f .(* SettingsFrame ); ! ok {
1393
- return ConnectionError (ErrCodeProtocol )
1393
+ return countError ( "first_settings" , ConnectionError (ErrCodeProtocol ) )
1394
1394
}
1395
1395
sc .sawFirstSettings = true
1396
1396
}
@@ -1415,7 +1415,7 @@ func (sc *serverConn) processFrame(f Frame) error {
1415
1415
case * PushPromiseFrame :
1416
1416
// A client cannot push. Thus, servers MUST treat the receipt of a PUSH_PROMISE
1417
1417
// frame as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
1418
- return ConnectionError (ErrCodeProtocol )
1418
+ return countError ( "push_promise" , ConnectionError (ErrCodeProtocol ) )
1419
1419
default :
1420
1420
sc .vlogf ("http2: server ignoring frame: %v" , f .Header ())
1421
1421
return nil
@@ -1435,7 +1435,7 @@ func (sc *serverConn) processPing(f *PingFrame) error {
1435
1435
// identifier field value other than 0x0, the recipient MUST
1436
1436
// respond with a connection error (Section 5.4.1) of type
1437
1437
// PROTOCOL_ERROR."
1438
- return ConnectionError (ErrCodeProtocol )
1438
+ return countError ( "ping_on_stream" , ConnectionError (ErrCodeProtocol ) )
1439
1439
}
1440
1440
if sc .inGoAway && sc .goAwayCode != ErrCodeNo {
1441
1441
return nil
@@ -1454,7 +1454,7 @@ func (sc *serverConn) processWindowUpdate(f *WindowUpdateFrame) error {
1454
1454
// or PRIORITY on a stream in this state MUST be
1455
1455
// treated as a connection error (Section 5.4.1) of
1456
1456
// type PROTOCOL_ERROR."
1457
- return ConnectionError (ErrCodeProtocol )
1457
+ return countError ( "stream_idle" , ConnectionError (ErrCodeProtocol ) )
1458
1458
}
1459
1459
if st == nil {
1460
1460
// "WINDOW_UPDATE can be sent by a peer that has sent a
@@ -1465,7 +1465,7 @@ func (sc *serverConn) processWindowUpdate(f *WindowUpdateFrame) error {
1465
1465
return nil
1466
1466
}
1467
1467
if ! st .flow .add (int32 (f .Increment )) {
1468
- return streamError (f .StreamID , ErrCodeFlowControl )
1468
+ return countError ( "bad_flow" , streamError (f .StreamID , ErrCodeFlowControl ) )
1469
1469
}
1470
1470
default : // connection-level flow control
1471
1471
if ! sc .flow .add (int32 (f .Increment )) {
@@ -1486,7 +1486,7 @@ func (sc *serverConn) processResetStream(f *RSTStreamFrame) error {
1486
1486
// identifying an idle stream is received, the
1487
1487
// recipient MUST treat this as a connection error
1488
1488
// (Section 5.4.1) of type PROTOCOL_ERROR.
1489
- return ConnectionError (ErrCodeProtocol )
1489
+ return countError ( "reset_idle_stream" , ConnectionError (ErrCodeProtocol ) )
1490
1490
}
1491
1491
if st != nil {
1492
1492
st .cancelCtx ()
@@ -1538,15 +1538,15 @@ func (sc *serverConn) processSettings(f *SettingsFrame) error {
1538
1538
// Why is the peer ACKing settings we never sent?
1539
1539
// The spec doesn't mention this case, but
1540
1540
// hang up on them anyway.
1541
- return ConnectionError (ErrCodeProtocol )
1541
+ return countError ( "ack_mystery" , ConnectionError (ErrCodeProtocol ) )
1542
1542
}
1543
1543
return nil
1544
1544
}
1545
1545
if f .NumSettings () > 100 || f .HasDuplicates () {
1546
1546
// This isn't actually in the spec, but hang up on
1547
1547
// suspiciously large settings frames or those with
1548
1548
// duplicate entries.
1549
- return ConnectionError (ErrCodeProtocol )
1549
+ return countError ( "settings_big_or_dups" , ConnectionError (ErrCodeProtocol ) )
1550
1550
}
1551
1551
if err := f .ForeachSetting (sc .processSetting ); err != nil {
1552
1552
return err
@@ -1613,7 +1613,7 @@ func (sc *serverConn) processSettingInitialWindowSize(val uint32) error {
1613
1613
// control window to exceed the maximum size as a
1614
1614
// connection error (Section 5.4.1) of type
1615
1615
// FLOW_CONTROL_ERROR."
1616
- return ConnectionError (ErrCodeFlowControl )
1616
+ return countError ( "setting_win_size" , ConnectionError (ErrCodeFlowControl ) )
1617
1617
}
1618
1618
}
1619
1619
return nil
@@ -1646,7 +1646,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
1646
1646
// or PRIORITY on a stream in this state MUST be
1647
1647
// treated as a connection error (Section 5.4.1) of
1648
1648
// type PROTOCOL_ERROR."
1649
- return ConnectionError (ErrCodeProtocol )
1649
+ return countError ( "data_on_idle" , ConnectionError (ErrCodeProtocol ) )
1650
1650
}
1651
1651
1652
1652
// "If a DATA frame is received whose stream is not in "open"
@@ -1663,7 +1663,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
1663
1663
// and return any flow control bytes since we're not going
1664
1664
// to consume them.
1665
1665
if sc .inflow .available () < int32 (f .Length ) {
1666
- return streamError (id , ErrCodeFlowControl )
1666
+ return countError ( "data_flow" , streamError (id , ErrCodeFlowControl ) )
1667
1667
}
1668
1668
// Deduct the flow control from inflow, since we're
1669
1669
// going to immediately add it back in
@@ -1676,7 +1676,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
1676
1676
// Already have a stream error in flight. Don't send another.
1677
1677
return nil
1678
1678
}
1679
- return streamError (id , ErrCodeStreamClosed )
1679
+ return countError ( "closed" , streamError (id , ErrCodeStreamClosed ) )
1680
1680
}
1681
1681
if st .body == nil {
1682
1682
panic ("internal error: should have a body in this state" )
@@ -1688,20 +1688,20 @@ func (sc *serverConn) processData(f *DataFrame) error {
1688
1688
// RFC 7540, sec 8.1.2.6: A request or response is also malformed if the
1689
1689
// value of a content-length header field does not equal the sum of the
1690
1690
// DATA frame payload lengths that form the body.
1691
- return streamError (id , ErrCodeProtocol )
1691
+ return countError ( "send_too_much" , streamError (id , ErrCodeProtocol ) )
1692
1692
}
1693
1693
if f .Length > 0 {
1694
1694
// Check whether the client has flow control quota.
1695
1695
if st .inflow .available () < int32 (f .Length ) {
1696
- return streamError (id , ErrCodeFlowControl )
1696
+ return countError ( "flow_on_data_length" , streamError (id , ErrCodeFlowControl ) )
1697
1697
}
1698
1698
st .inflow .take (int32 (f .Length ))
1699
1699
1700
1700
if len (data ) > 0 {
1701
1701
wrote , err := st .body .Write (data )
1702
1702
if err != nil {
1703
1703
sc .sendWindowUpdate (nil , int (f .Length )- wrote )
1704
- return streamError (id , ErrCodeStreamClosed )
1704
+ return countError ( "body_write_err" , streamError (id , ErrCodeStreamClosed ) )
1705
1705
}
1706
1706
if wrote != len (data ) {
1707
1707
panic ("internal error: bad Writer" )
@@ -1787,7 +1787,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
1787
1787
// stream identifier MUST respond with a connection error
1788
1788
// (Section 5.4.1) of type PROTOCOL_ERROR.
1789
1789
if id % 2 != 1 {
1790
- return ConnectionError (ErrCodeProtocol )
1790
+ return countError ( "headers_even" , ConnectionError (ErrCodeProtocol ) )
1791
1791
}
1792
1792
// A HEADERS frame can be used to create a new stream or
1793
1793
// send a trailer for an open one. If we already have a stream
@@ -1804,7 +1804,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
1804
1804
// this state, it MUST respond with a stream error (Section 5.4.2) of
1805
1805
// type STREAM_CLOSED.
1806
1806
if st .state == stateHalfClosedRemote {
1807
- return streamError (id , ErrCodeStreamClosed )
1807
+ return countError ( "headers_half_closed" , streamError (id , ErrCodeStreamClosed ) )
1808
1808
}
1809
1809
return st .processTrailerHeaders (f )
1810
1810
}
@@ -1815,7 +1815,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
1815
1815
// receives an unexpected stream identifier MUST respond with
1816
1816
// a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
1817
1817
if id <= sc .maxClientStreamID {
1818
- return ConnectionError (ErrCodeProtocol )
1818
+ return countError ( "stream_went_down" , ConnectionError (ErrCodeProtocol ) )
1819
1819
}
1820
1820
sc .maxClientStreamID = id
1821
1821
@@ -1832,14 +1832,14 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
1832
1832
if sc .curClientStreams + 1 > sc .advMaxStreams {
1833
1833
if sc .unackedSettings == 0 {
1834
1834
// They should know better.
1835
- return streamError (id , ErrCodeProtocol )
1835
+ return countError ( "over_max_streams" , streamError (id , ErrCodeProtocol ) )
1836
1836
}
1837
1837
// Assume it's a network race, where they just haven't
1838
1838
// received our last SETTINGS update. But actually
1839
1839
// this can't happen yet, because we don't yet provide
1840
1840
// a way for users to adjust server parameters at
1841
1841
// runtime.
1842
- return streamError (id , ErrCodeRefusedStream )
1842
+ return countError ( "over_max_streams_race" , streamError (id , ErrCodeRefusedStream ) )
1843
1843
}
1844
1844
1845
1845
initialState := stateOpen
@@ -1893,15 +1893,15 @@ func (st *stream) processTrailerHeaders(f *MetaHeadersFrame) error {
1893
1893
sc := st .sc
1894
1894
sc .serveG .check ()
1895
1895
if st .gotTrailerHeader {
1896
- return ConnectionError (ErrCodeProtocol )
1896
+ return countError ( "dup_trailers" , ConnectionError (ErrCodeProtocol ) )
1897
1897
}
1898
1898
st .gotTrailerHeader = true
1899
1899
if ! f .StreamEnded () {
1900
- return streamError (st .id , ErrCodeProtocol )
1900
+ return countError ( "trailers_not_ended" , streamError (st .id , ErrCodeProtocol ) )
1901
1901
}
1902
1902
1903
1903
if len (f .PseudoFields ()) > 0 {
1904
- return streamError (st .id , ErrCodeProtocol )
1904
+ return countError ( "trailers_pseudo" , streamError (st .id , ErrCodeProtocol ) )
1905
1905
}
1906
1906
if st .trailer != nil {
1907
1907
for _ , hf := range f .RegularFields () {
@@ -1910,7 +1910,7 @@ func (st *stream) processTrailerHeaders(f *MetaHeadersFrame) error {
1910
1910
// TODO: send more details to the peer somehow. But http2 has
1911
1911
// no way to send debug data at a stream level. Discuss with
1912
1912
// HTTP folk.
1913
- return streamError (st .id , ErrCodeProtocol )
1913
+ return countError ( "trailers_bogus" , streamError (st .id , ErrCodeProtocol ) )
1914
1914
}
1915
1915
st .trailer [key ] = append (st .trailer [key ], hf .Value )
1916
1916
}
@@ -1925,7 +1925,7 @@ func checkPriority(streamID uint32, p PriorityParam) error {
1925
1925
// this as a stream error (Section 5.4.2) of type PROTOCOL_ERROR."
1926
1926
// Section 5.3.3 says that a stream can depend on one of its dependencies,
1927
1927
// so it's only self-dependencies that are forbidden.
1928
- return streamError (streamID , ErrCodeProtocol )
1928
+ return countError ( "priority" , streamError (streamID , ErrCodeProtocol ) )
1929
1929
}
1930
1930
return nil
1931
1931
}
@@ -2004,13 +2004,13 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2004
2004
// "All HTTP/2 requests MUST include exactly one valid
2005
2005
// value for the :method, :scheme, and :path
2006
2006
// pseudo-header fields"
2007
- return nil , nil , streamError (f .StreamID , ErrCodeProtocol )
2007
+ return nil , nil , countError ( "bad_path_method" , streamError (f .StreamID , ErrCodeProtocol ) )
2008
2008
}
2009
2009
2010
2010
bodyOpen := ! f .StreamEnded ()
2011
2011
if rp .method == "HEAD" && bodyOpen {
2012
2012
// HEAD requests can't have bodies
2013
- return nil , nil , streamError (f .StreamID , ErrCodeProtocol )
2013
+ return nil , nil , countError ( "head_body" , streamError (f .StreamID , ErrCodeProtocol ) )
2014
2014
}
2015
2015
2016
2016
rp .header = make (http.Header )
@@ -2093,7 +2093,7 @@ func (sc *serverConn) newWriterAndRequestNoBody(st *stream, rp requestParam) (*r
2093
2093
var err error
2094
2094
url_ , err = url .ParseRequestURI (rp .path )
2095
2095
if err != nil {
2096
- return nil , nil , streamError (st .id , ErrCodeProtocol )
2096
+ return nil , nil , countError ( "bad_path" , streamError (st .id , ErrCodeProtocol ) )
2097
2097
}
2098
2098
requestURI = rp .path
2099
2099
}
0 commit comments