File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -575,6 +575,11 @@ impl Pseudo {
575
575
}
576
576
}
577
577
578
+ #[ cfg( feature = "unstable" ) ]
579
+ pub fn set_status ( & mut self , value : StatusCode ) {
580
+ self . status = Some ( value) ;
581
+ }
582
+
578
583
pub fn set_scheme ( & mut self , scheme : uri:: Scheme ) {
579
584
let bytes_str = match scheme. as_str ( ) {
580
585
"http" => BytesStr :: from_static ( "http" ) ,
Original file line number Diff line number Diff line change @@ -1410,10 +1410,8 @@ impl proto::Peer for Peer {
1410
1410
malformed ! ( "malformed headers: missing method" ) ;
1411
1411
}
1412
1412
1413
- // Specifying :status for a request is a protocol error
1414
1413
if pseudo. status . is_some ( ) {
1415
- tracing:: trace!( "malformed headers: :status field on request; PROTOCOL_ERROR" ) ;
1416
- return Err ( Error :: library_go_away ( Reason :: PROTOCOL_ERROR ) ) ;
1414
+ malformed ! ( "malformed headers: :status field on request" ) ;
1417
1415
}
1418
1416
1419
1417
// Convert the URI
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::convert::TryInto;
2
2
use std:: fmt;
3
3
4
4
use bytes:: Bytes ;
5
- use http:: { self , HeaderMap } ;
5
+ use http:: { self , HeaderMap , StatusCode } ;
6
6
7
7
use h2:: frame:: { self , Frame , StreamId } ;
8
8
@@ -162,6 +162,14 @@ impl Mock<frame::Headers> {
162
162
Mock ( frame)
163
163
}
164
164
165
+ pub fn status ( self , value : StatusCode ) -> Self {
166
+ let ( id, mut pseudo, fields) = self . into_parts ( ) ;
167
+
168
+ pseudo. set_status ( value) ;
169
+
170
+ Mock ( frame:: Headers :: new ( id, pseudo, fields) )
171
+ }
172
+
165
173
pub fn scheme ( self , value : & str ) -> Self {
166
174
let ( id, mut pseudo, fields) = self . into_parts ( ) ;
167
175
let value = value. parse ( ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -1025,6 +1025,30 @@ async fn server_error_on_unclean_shutdown() {
1025
1025
srv. await . expect_err ( "should error" ) ;
1026
1026
}
1027
1027
1028
+ #[ tokio:: test]
1029
+ async fn server_error_on_status_in_request ( ) {
1030
+ h2_support:: trace_init!( ) ;
1031
+
1032
+ let ( io, mut client) = mock:: new ( ) ;
1033
+
1034
+ let client = async move {
1035
+ let settings = client. assert_server_handshake ( ) . await ;
1036
+ assert_default_settings ! ( settings) ;
1037
+ client
1038
+ . send_frame ( frames:: headers ( 1 ) . status ( StatusCode :: OK ) )
1039
+ . await ;
1040
+ client. recv_frame ( frames:: reset ( 1 ) . protocol_error ( ) ) . await ;
1041
+ } ;
1042
+
1043
+ let srv = async move {
1044
+ let mut srv = server:: handshake ( io) . await . expect ( "handshake" ) ;
1045
+
1046
+ assert ! ( srv. next( ) . await . is_none( ) ) ;
1047
+ } ;
1048
+
1049
+ join ( client, srv) . await ;
1050
+ }
1051
+
1028
1052
#[ tokio:: test]
1029
1053
async fn request_without_authority ( ) {
1030
1054
h2_support:: trace_init!( ) ;
You can’t perform that action at this time.
0 commit comments