@@ -3125,3 +3125,82 @@ func (s) TestServerSendsRSTAfterDeadlineToMisbehavedClient(t *testing.T) {
3125
3125
t .Fatalf ("RST frame received earlier than expected by duration: %v" , want - got )
3126
3126
}
3127
3127
}
3128
+
3129
+ // TestClientTransport_Handle1xxHeaders validates that 1xx HTTP status headers
3130
+ // are ignored and treated as a protocol error if END_STREAM is set.
3131
+ func (s ) TestClientTransport_Handle1xxHeaders (t * testing.T ) {
3132
+ testStream := func () * ClientStream {
3133
+ return & ClientStream {
3134
+ Stream : & Stream {
3135
+ buf : & recvBuffer {
3136
+ c : make (chan recvMsg ),
3137
+ mu : sync.Mutex {},
3138
+ },
3139
+ },
3140
+ done : make (chan struct {}),
3141
+ headerChan : make (chan struct {}),
3142
+ }
3143
+ }
3144
+
3145
+ testClient := func (ts * ClientStream ) * http2Client {
3146
+ return & http2Client {
3147
+ mu : sync.Mutex {},
3148
+ activeStreams : map [uint32 ]* ClientStream {
3149
+ 0 : ts ,
3150
+ },
3151
+ controlBuf : newControlBuffer (make (<- chan struct {})),
3152
+ }
3153
+ }
3154
+
3155
+ for _ , test := range []struct {
3156
+ name string
3157
+ metaHeaderFrame * http2.MetaHeadersFrame
3158
+ httpFlags http2.Flags
3159
+ wantStatus * status.Status
3160
+ }{
3161
+ {
3162
+ name : "1xx with END_STREAM is error" ,
3163
+ metaHeaderFrame : & http2.MetaHeadersFrame {
3164
+ Fields : []hpack.HeaderField {
3165
+ {Name : ":status" , Value : "100" },
3166
+ },
3167
+ },
3168
+ httpFlags : http2 .FlagHeadersEndStream ,
3169
+ wantStatus : status .New (
3170
+ codes .Internal ,
3171
+ "protocol error: informational header with status code 100 must not have END_STREAM set" ,
3172
+ ),
3173
+ },
3174
+ {
3175
+ name : "1xx without END_STREAM is ignored" ,
3176
+ metaHeaderFrame : & http2.MetaHeadersFrame {
3177
+ Fields : []hpack.HeaderField {
3178
+ {Name : ":status" , Value : "100" },
3179
+ },
3180
+ },
3181
+ httpFlags : 0 ,
3182
+ wantStatus : nil ,
3183
+ },
3184
+ } {
3185
+ t .Run (test .name , func (t * testing.T ) {
3186
+ ts := testStream ()
3187
+ s := testClient (ts )
3188
+
3189
+ test .metaHeaderFrame .HeadersFrame = & http2.HeadersFrame {
3190
+ FrameHeader : http2.FrameHeader {
3191
+ StreamID : 0 ,
3192
+ Flags : test .httpFlags ,
3193
+ },
3194
+ }
3195
+
3196
+ s .operateHeaders (test .metaHeaderFrame )
3197
+
3198
+ got := ts .status
3199
+ want := test .wantStatus
3200
+
3201
+ if got .Code () != want .Code () || got .Message () != want .Message () {
3202
+ t .Fatalf ("operateHeaders(%v); status = %v, want %v" , test .metaHeaderFrame , got , want )
3203
+ }
3204
+ })
3205
+ }
3206
+ }
0 commit comments