@@ -37,11 +37,17 @@ pub(crate) struct Encoder {
37
37
38
38
#[ derive( Debug ) ]
39
39
enum State {
40
+ /// Starting state.
40
41
Init ,
42
+ /// Write the HEAD section to an intermediate buffer.
41
43
ComputeHead ,
44
+ /// Stream out the HEAD section.
42
45
EncodeHead ,
43
- FixedBody ,
44
- ChunkedBody ,
46
+ /// Stream out a body whose length is known ahead of time.
47
+ EncodeFixedBody ,
48
+ /// Stream out a body whose length is *not* know ahead of time.
49
+ EncodeChunkedBody ,
50
+ /// Stream has ended.
45
51
End ,
46
52
}
47
53
@@ -70,8 +76,8 @@ impl Encoder {
70
76
State :: Init => self . init ( cx, buf) ,
71
77
State :: ComputeHead => self . compute_head ( cx, buf) ,
72
78
State :: EncodeHead => self . encode_head ( cx, buf) ,
73
- State :: FixedBody => self . encode_fixed_body ( cx, buf) ,
74
- State :: ChunkedBody => self . encode_chunked_body ( cx, buf) ,
79
+ State :: EncodeFixedBody => self . encode_fixed_body ( cx, buf) ,
80
+ State :: EncodeChunkedBody => self . encode_chunked_body ( cx, buf) ,
75
81
State :: End => Poll :: Ready ( Ok ( self . bytes_written ) ) ,
76
82
} ;
77
83
log:: trace!( "ServerEncoder {} bytes written" , self . bytes_written) ;
@@ -87,9 +93,9 @@ impl Encoder {
87
93
match self . state {
88
94
Init => assert ! ( matches!( state, ComputeHead ) ) ,
89
95
ComputeHead => assert ! ( matches!( state, EncodeHead ) ) ,
90
- EncodeHead => assert ! ( matches!( state, ChunkedBody | FixedBody ) ) ,
91
- FixedBody => assert ! ( matches!( state, End ) ) ,
92
- ChunkedBody => assert ! ( matches!( state, End ) ) ,
96
+ EncodeHead => assert ! ( matches!( state, EncodeChunkedBody | EncodeFixedBody ) ) ,
97
+ EncodeFixedBody => assert ! ( matches!( state, End ) ) ,
98
+ EncodeChunkedBody => assert ! ( matches!( state, End ) ) ,
93
99
End => panic ! ( "No state transitions allowed after the stream has ended" ) ,
94
100
}
95
101
@@ -158,12 +164,12 @@ impl Encoder {
158
164
match self . res . len ( ) {
159
165
Some ( body_len) => {
160
166
self . body_len = body_len;
161
- self . state = State :: FixedBody ;
167
+ self . state = State :: EncodeFixedBody ;
162
168
log:: trace!( "Server response encoding: fixed length body" ) ;
163
169
return self . encode_fixed_body ( cx, buf) ;
164
170
}
165
171
None => {
166
- self . state = State :: ChunkedBody ;
172
+ self . state = State :: EncodeChunkedBody ;
167
173
log:: trace!( "Server response encoding: chunked body" ) ;
168
174
return self . encode_chunked_body ( cx, buf) ;
169
175
}
0 commit comments