@@ -2,7 +2,7 @@ use std::{cell::RefCell, rc::Rc};
22
33use ntex_bytes:: { Buf , BufMut , ByteString , BytesMut } ;
44use ntex_h2:: { self as h2, StreamRef , frame:: Reason , frame:: StreamId } ;
5- use ntex_http:: { HeaderMap , HeaderValue , StatusCode } ;
5+ use ntex_http:: { HeaderMap , HeaderValue , StatusCode , header :: CONTENT_TYPE } ;
66use ntex_io:: { Filter , Io , IoBoxed } ;
77use ntex_service:: { Service , ServiceCtx , ServiceFactory , cfg:: SharedCfg } ;
88use ntex_util:: { HashMap , time:: Millis , time:: timeout_checked} ;
@@ -18,6 +18,7 @@ const ERR_DATA_DECODE: HeaderValue =
1818const ERR_DECODE_TIMEOUT : HeaderValue =
1919 HeaderValue :: from_static ( "Cannot decode grpc-timeout header" ) ;
2020const ERR_DEADLINE : HeaderValue = HeaderValue :: from_static ( "Deadline exceeded" ) ;
21+ const HDR_APP_GRPC : HeaderValue = HeaderValue :: from_static ( "application/grpc" ) ;
2122
2223const MILLIS_IN_HOUR : u64 = 60 * 60 * 1000 ;
2324const MILLIS_IN_MINUTE : u64 = 60 * 1000 ;
@@ -187,17 +188,13 @@ where
187188 path. split_to ( n)
188189 } else {
189190 // not found
190- let _ =
191- stream. send_response ( StatusCode :: NOT_FOUND , HeaderMap :: default ( ) , true ) ;
191+ let _ = stream. send_response ( StatusCode :: NOT_FOUND , hdrs ( ) , true ) ;
192192 return Ok ( ( ) ) ;
193193 } ;
194194
195195 // stream eof, cannot do anything
196196 if eof {
197- if stream
198- . send_response ( StatusCode :: OK , HeaderMap :: default ( ) , false )
199- . is_ok ( )
200- {
197+ if stream. send_response ( StatusCode :: OK , hdrs ( ) , false ) . is_ok ( ) {
201198 send_error ( & stream, GrpcStatus :: InvalidArgument , ERR_DECODE ) ;
202199 }
203200 return Ok ( ( ) ) ;
@@ -241,10 +238,7 @@ where
241238 let _compressed = data. get_u8 ( ) ;
242239 let len = data. get_u32 ( ) ;
243240 if ( len as usize ) > data. len ( ) {
244- if stream
245- . send_response ( StatusCode :: OK , HeaderMap :: default ( ) , false )
246- . is_ok ( )
247- {
241+ if stream. send_response ( StatusCode :: OK , hdrs ( ) , false ) . is_ok ( ) {
248242 send_error ( & stream, GrpcStatus :: InvalidArgument , ERR_DATA_DECODE ) ;
249243 }
250244 return Ok ( ( ) ) ;
@@ -264,10 +258,7 @@ where
264258 name : inflight. name ,
265259 headers : inflight. headers ,
266260 } ;
267- if stream
268- . send_response ( StatusCode :: OK , HeaderMap :: default ( ) , false )
269- . is_err ( )
270- {
261+ if stream. send_response ( StatusCode :: OK , hdrs ( ) , false ) . is_err ( ) {
271262 return Ok ( ( ) ) ;
272263 }
273264 drop ( streams) ;
@@ -333,6 +324,12 @@ where
333324 }
334325}
335326
327+ fn hdrs ( ) -> HeaderMap {
328+ let mut hdrs = HeaderMap :: default ( ) ;
329+ hdrs. insert ( CONTENT_TYPE , HDR_APP_GRPC ) ;
330+ hdrs
331+ }
332+
336333fn send_error ( stream : & StreamRef , st : GrpcStatus , msg : HeaderValue ) {
337334 let mut trailers = HeaderMap :: default ( ) ;
338335 trailers. insert ( consts:: GRPC_STATUS , st. into ( ) ) ;
0 commit comments