From ea0050e2a2e3677986dec7ad18af227ae193f1f1 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 23 Oct 2019 09:40:19 +0700 Subject: [PATCH] update HTTP/3 errors * rename HTTP_UNEXPECTED_FRAME to HTTP_FRAME_UNEXPECTED * remove the HTTP_WRONG_STREAM error * rename errors from HTTP_ to H3_ --- http3/client.go | 2 +- http3/client_test.go | 2 +- http3/error_codes.go | 59 ++++++++++++++---------------- http3/server.go | 2 +- http3/server_test.go | 2 +- integrationtests/self/http_test.go | 2 +- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/http3/client.go b/http3/client.go index 49b838771..a105f51c9 100644 --- a/http3/client.go +++ b/http3/client.go @@ -204,7 +204,7 @@ func (c *client) doRequest( } hf, ok := frame.(*headersFrame) if !ok { - return nil, newConnError(errorUnexpectedFrame, errors.New("expected first frame to be a HEADERS frame")) + return nil, newConnError(errorFrameUnexpected, errors.New("expected first frame to be a HEADERS frame")) } if hf.Length > c.maxHeaderBytes() { return nil, newStreamError(errorFrameError, fmt.Errorf("HEADERS frame too large: %d bytes (max: %d)", hf.Length, c.maxHeaderBytes())) diff --git a/http3/client_test.go b/http3/client_test.go index c22e76353..607aba057 100644 --- a/http3/client_test.go +++ b/http3/client_test.go @@ -271,7 +271,7 @@ var _ = Describe("Client", func() { It("closes the connection when the first frame is not a HEADERS frame", func() { buf := &bytes.Buffer{} (&dataFrame{Length: 0x42}).Write(buf) - sess.EXPECT().CloseWithError(quic.ErrorCode(errorUnexpectedFrame), gomock.Any()) + sess.EXPECT().CloseWithError(quic.ErrorCode(errorFrameUnexpected), gomock.Any()) closed := make(chan struct{}) str.EXPECT().Close().Do(func() { close(closed) }) str.EXPECT().Read(gomock.Any()).DoAndReturn(func(b []byte) (int, error) { diff --git a/http3/error_codes.go b/http3/error_codes.go index a26189b90..2e8f4f810 100644 --- a/http3/error_codes.go +++ b/http3/error_codes.go @@ -14,59 +14,56 @@ const ( errorInternalError errorCode = 0x102 errorStreamCreationError errorCode = 0x103 errorClosedCriticalStream errorCode = 0x104 - errorUnexpectedFrame errorCode = 0x105 + errorFrameUnexpected errorCode = 0x105 errorFrameError errorCode = 0x106 errorExcessiveLoad errorCode = 0x107 - errorWrongStream errorCode = 0x108 - errorIDError errorCode = 0x109 - errorSettingsError errorCode = 0x10a - errorMissingSettings errorCode = 0x10b - errorRequestRejected errorCode = 0x10c - errorRequestCanceled errorCode = 0x10d - errorRequestIncomplete errorCode = 0x10e - errorEarlyResponse errorCode = 0x10f - errorConnectError errorCode = 0x110 - errorVersionFallback errorCode = 0x111 + errorIDError errorCode = 0x108 + errorSettingsError errorCode = 0x109 + errorMissingSettings errorCode = 0x10a + errorRequestRejected errorCode = 0x10b + errorRequestCanceled errorCode = 0x10c + errorRequestIncomplete errorCode = 0x10d + errorEarlyResponse errorCode = 0x10e + errorConnectError errorCode = 0x10f + errorVersionFallback errorCode = 0x110 ) func (e errorCode) String() string { switch e { case errorNoError: - return "HTTP_NO_ERROR" + return "H3_NO_ERROR" case errorGeneralProtocolError: - return "HTTP_GENERAL_PROTOCOL_ERROR" + return "H3_GENERAL_PROTOCOL_ERROR" case errorInternalError: - return "HTTP_INTERNAL_ERROR" + return "H3_INTERNAL_ERROR" case errorStreamCreationError: - return "HTTP_STREAM_CREATION_ERROR" + return "H3_STREAM_CREATION_ERROR" case errorClosedCriticalStream: - return "HTTP_CLOSED_CRITICAL_STREAM" - case errorUnexpectedFrame: - return "HTTP_UNEXPECTED_FRAME" + return "H3_CLOSED_CRITICAL_STREAM" + case errorFrameUnexpected: + return "H3_FRAME_UNEXPECTED" case errorFrameError: - return "HTTP_FRAME_ERROR" + return "H3_FRAME_ERROR" case errorExcessiveLoad: - return "HTTP_EXCESSIVE_LOAD" - case errorWrongStream: - return "HTTP_WRONG_STREAM" + return "H3_EXCESSIVE_LOAD" case errorIDError: - return "HTTP_ID_ERROR" + return "H3_ID_ERROR" case errorSettingsError: - return "HTTP_SETTINGS_ERROR" + return "H3_SETTINGS_ERROR" case errorMissingSettings: - return "HTTP_MISSING_SETTINGS" + return "H3_MISSING_SETTINGS" case errorRequestRejected: - return "HTTP_REQUEST_REJECTED" + return "H3_REQUEST_REJECTED" case errorRequestCanceled: - return "HTTP_REQUEST_CANCELLED" + return "H3_REQUEST_CANCELLED" case errorRequestIncomplete: - return "HTTP_INCOMPLETE_REQUEST" + return "H3_INCOMPLETE_REQUEST" case errorEarlyResponse: - return "HTTP_EARLY_RESPONSE" + return "H3_EARLY_RESPONSE" case errorConnectError: - return "HTTP_CONNECT_ERROR" + return "H3_CONNECT_ERROR" case errorVersionFallback: - return "HTTP_VERSION_FALLBACK" + return "H3_VERSION_FALLBACK" default: return fmt.Sprintf("unknown error code: %#x", uint16(e)) } diff --git a/http3/server.go b/http3/server.go index 4610e4241..bd2ad8e0a 100644 --- a/http3/server.go +++ b/http3/server.go @@ -213,7 +213,7 @@ func (s *Server) handleRequest(str quic.Stream, decoder *qpack.Decoder) requestE } hf, ok := frame.(*headersFrame) if !ok { - return newConnError(errorUnexpectedFrame, errors.New("expected first frame to be a HEADERS frame")) + return newConnError(errorFrameUnexpected, errors.New("expected first frame to be a HEADERS frame")) } if hf.Length > s.maxHeaderBytes() { return newStreamError(errorFrameError, fmt.Errorf("HEADERS frame too large: %d bytes (max: %d)", hf.Length, s.maxHeaderBytes())) diff --git a/http3/server_test.go b/http3/server_test.go index 7a6f4aa61..985c83547 100644 --- a/http3/server_test.go +++ b/http3/server_test.go @@ -248,7 +248,7 @@ var _ = Describe("Server", func() { done := make(chan struct{}) sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ErrorCode, _ string) { - Expect(code).To(Equal(quic.ErrorCode(errorUnexpectedFrame))) + Expect(code).To(Equal(quic.ErrorCode(errorFrameUnexpected))) close(done) }) s.handleConn(sess) diff --git a/integrationtests/self/http_test.go b/integrationtests/self/http_test.go index 0074e54ba..6172f4f01 100644 --- a/integrationtests/self/http_test.go +++ b/integrationtests/self/http_test.go @@ -202,7 +202,7 @@ var _ = Describe("HTTP tests", func() { serr, ok := err.(streamCancelError) Expect(ok).To(BeTrue()) Expect(serr.Canceled()).To(BeTrue()) - Expect(serr.ErrorCode()).To(BeEquivalentTo(0x10d)) + Expect(serr.ErrorCode()).To(BeEquivalentTo(0x10c)) return } }