@@ -45,7 +45,7 @@ extension HPACKHeaders {
4545 GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
4646 GRPCHTTP2Keys . method. rawValue: " POST " ,
4747 GRPCHTTP2Keys . scheme. rawValue: " https " ,
48- GRPCHTTP2Keys . te. rawValue: " te " ,
48+ GRPCHTTP2Keys . te. rawValue: " trailers " ,
4949 GRPCHTTP2Keys . acceptEncoding. rawValue: " deflate " ,
5050 GRPCHTTP2Keys . encoding. rawValue: " deflate " ,
5151 ]
@@ -54,7 +54,7 @@ extension HPACKHeaders {
5454 GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
5555 GRPCHTTP2Keys . method. rawValue: " POST " ,
5656 GRPCHTTP2Keys . scheme. rawValue: " https " ,
57- GRPCHTTP2Keys . te. rawValue: " te " ,
57+ GRPCHTTP2Keys . te. rawValue: " trailers " ,
5858 GRPCHTTP2Keys . acceptEncoding. rawValue: " gzip " ,
5959 GRPCHTTP2Keys . encoding. rawValue: " gzip " ,
6060 ]
@@ -68,6 +68,45 @@ extension HPACKHeaders {
6868 fileprivate static let receivedWithoutEndpoint : Self = [
6969 GRPCHTTP2Keys . contentType. rawValue: " application/grpc "
7070 ]
71+ fileprivate static let receivedWithoutTE : Self = [
72+ GRPCHTTP2Keys . path. rawValue: " test/test " ,
73+ GRPCHTTP2Keys . scheme. rawValue: " http " ,
74+ GRPCHTTP2Keys . method. rawValue: " POST " ,
75+ GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
76+ ]
77+ fileprivate static let receivedWithInvalidTE : Self = [
78+ GRPCHTTP2Keys . path. rawValue: " test/test " ,
79+ GRPCHTTP2Keys . scheme. rawValue: " http " ,
80+ GRPCHTTP2Keys . method. rawValue: " POST " ,
81+ GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
82+ GRPCHTTP2Keys . te. rawValue: " invalidte " ,
83+ ]
84+ fileprivate static let receivedWithoutMethod : Self = [
85+ GRPCHTTP2Keys . path. rawValue: " test/test " ,
86+ GRPCHTTP2Keys . scheme. rawValue: " http " ,
87+ GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
88+ GRPCHTTP2Keys . te. rawValue: " trailers " ,
89+ ]
90+ fileprivate static let receivedWithInvalidMethod : Self = [
91+ GRPCHTTP2Keys . path. rawValue: " test/test " ,
92+ GRPCHTTP2Keys . scheme. rawValue: " http " ,
93+ GRPCHTTP2Keys . method. rawValue: " GET " ,
94+ GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
95+ GRPCHTTP2Keys . te. rawValue: " trailers " ,
96+ ]
97+ fileprivate static let receivedWithoutScheme : Self = [
98+ GRPCHTTP2Keys . path. rawValue: " test/test " ,
99+ GRPCHTTP2Keys . method. rawValue: " POST " ,
100+ GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
101+ GRPCHTTP2Keys . te. rawValue: " trailers " ,
102+ ]
103+ fileprivate static let receivedWithInvalidScheme : Self = [
104+ GRPCHTTP2Keys . path. rawValue: " test/test " ,
105+ GRPCHTTP2Keys . scheme. rawValue: " invalidscheme " ,
106+ GRPCHTTP2Keys . method. rawValue: " POST " ,
107+ GRPCHTTP2Keys . contentType. rawValue: " application/grpc " ,
108+ GRPCHTTP2Keys . te. rawValue: " trailers " ,
109+ ]
71110
72111 // Server
73112 fileprivate static let serverInitialMetadata : Self = [
@@ -1502,6 +1541,136 @@ final class GRPCStreamServerStateMachineTests: XCTestCase {
15021541 }
15031542 }
15041543
1544+ func testReceiveMetadataWhenClientIdleAndServerIdle_MissingTE( ) throws {
1545+ var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
1546+
1547+ let action = try stateMachine. receive (
1548+ metadata: . receivedWithoutTE,
1549+ endStream: false
1550+ )
1551+
1552+ self . assertRejectedRPC ( action) { trailers in
1553+ XCTAssertEqual (
1554+ trailers,
1555+ [
1556+ " :status " : " 200 " ,
1557+ " content-type " : " application/grpc " ,
1558+ " grpc-status " : " 3 " ,
1559+ " grpc-status-message " :
1560+ " \" te \" header is expected to be present and have a value of \" trailers \" . " ,
1561+ ]
1562+ )
1563+ }
1564+ }
1565+
1566+ func testReceiveMetadataWhenClientIdleAndServerIdle_InvalidTE( ) throws {
1567+ var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
1568+
1569+ let action = try stateMachine. receive (
1570+ metadata: . receivedWithInvalidTE,
1571+ endStream: false
1572+ )
1573+
1574+ self . assertRejectedRPC ( action) { trailers in
1575+ XCTAssertEqual (
1576+ trailers,
1577+ [
1578+ " :status " : " 200 " ,
1579+ " content-type " : " application/grpc " ,
1580+ " grpc-status " : " 3 " ,
1581+ " grpc-status-message " :
1582+ " \" te \" header is expected to be present and have a value of \" trailers \" . " ,
1583+ ]
1584+ )
1585+ }
1586+ }
1587+
1588+ func testReceiveMetadataWhenClientIdleAndServerIdle_MissingMethod( ) throws {
1589+ var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
1590+
1591+ let action = try stateMachine. receive (
1592+ metadata: . receivedWithoutMethod,
1593+ endStream: false
1594+ )
1595+
1596+ self . assertRejectedRPC ( action) { trailers in
1597+ XCTAssertEqual (
1598+ trailers,
1599+ [
1600+ " :status " : " 200 " ,
1601+ " content-type " : " application/grpc " ,
1602+ " grpc-status " : " 3 " ,
1603+ " grpc-status-message " :
1604+ " :method header is expected to be present and have a value of \" POST \" . " ,
1605+ ]
1606+ )
1607+ }
1608+ }
1609+
1610+ func testReceiveMetadataWhenClientIdleAndServerIdle_InvalidMethod( ) throws {
1611+ var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
1612+
1613+ let action = try stateMachine. receive (
1614+ metadata: . receivedWithInvalidMethod,
1615+ endStream: false
1616+ )
1617+
1618+ self . assertRejectedRPC ( action) { trailers in
1619+ XCTAssertEqual (
1620+ trailers,
1621+ [
1622+ " :status " : " 200 " ,
1623+ " content-type " : " application/grpc " ,
1624+ " grpc-status " : " 3 " ,
1625+ " grpc-status-message " :
1626+ " :method header is expected to be present and have a value of \" POST \" . " ,
1627+ ]
1628+ )
1629+ }
1630+ }
1631+
1632+ func testReceiveMetadataWhenClientIdleAndServerIdle_MissingScheme( ) throws {
1633+ var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
1634+
1635+ let action = try stateMachine. receive (
1636+ metadata: . receivedWithoutScheme,
1637+ endStream: false
1638+ )
1639+
1640+ self . assertRejectedRPC ( action) { trailers in
1641+ XCTAssertEqual (
1642+ trailers,
1643+ [
1644+ " :status " : " 200 " ,
1645+ " content-type " : " application/grpc " ,
1646+ " grpc-status " : " 3 " ,
1647+ " grpc-status-message " : " :scheme header must be present and one of \" http \" or \" https \" . " ,
1648+ ]
1649+ )
1650+ }
1651+ }
1652+
1653+ func testReceiveMetadataWhenClientIdleAndServerIdle_InvalidScheme( ) throws {
1654+ var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
1655+
1656+ let action = try stateMachine. receive (
1657+ metadata: . receivedWithInvalidScheme,
1658+ endStream: false
1659+ )
1660+
1661+ self . assertRejectedRPC ( action) { trailers in
1662+ XCTAssertEqual (
1663+ trailers,
1664+ [
1665+ " :status " : " 200 " ,
1666+ " content-type " : " application/grpc " ,
1667+ " grpc-status " : " 3 " ,
1668+ " grpc-status-message " : " :scheme header must be present and one of \" http \" or \" https \" . " ,
1669+ ]
1670+ )
1671+ }
1672+ }
1673+
15051674 func testReceiveMetadataWhenClientIdleAndServerIdle_ServerUnsupportedEncoding( ) throws {
15061675 var stateMachine = self . makeServerStateMachine ( targetState: . clientIdleServerIdle)
15071676
0 commit comments