@@ -38,6 +38,7 @@ pub struct Server<State> {
3838 /// We don't use a Mutex around the Vec here because adding a middleware during execution should be an error.
3939 #[ allow( clippy:: rc_buffer) ]
4040 middleware : Arc < Vec < Arc < dyn Middleware < State > > > > ,
41+ tcp_nodelay : bool ,
4142}
4243
4344impl Server < ( ) > {
@@ -113,6 +114,7 @@ where
113114 Arc :: new( log:: LogMiddleware :: new( ) ) ,
114115 ] ) ,
115116 state,
117+ tcp_nodelay : false ,
116118 }
117119 }
118120
@@ -286,6 +288,7 @@ where
286288 router,
287289 state,
288290 middleware,
291+ tcp_nodelay : _tcp_nodelay,
289292 } = self . clone ( ) ;
290293
291294 let method = req. method ( ) . to_owned ( ) ;
@@ -317,6 +320,31 @@ where
317320 pub fn state ( & self ) -> & State {
318321 & self . state
319322 }
323+
324+ /// Gets the value of the TCP_NODELAY option for tcp connections.
325+ pub fn tcp_nodelay ( & self ) -> bool {
326+ self . tcp_nodelay
327+ }
328+
329+ /// Set the TCP_NODELAY option for tcp connections.
330+ ///
331+ /// # Examples
332+ ///
333+ /// ```no_run
334+ /// # use async_std::task::block_on;
335+ /// # fn main() -> Result<(), std::io::Error> { block_on(async {
336+ /// #
337+ /// let mut app = tide::new();
338+ /// app.at("/").get(|_| async { Ok("Hello, world!") });
339+ /// app.set_tcp_nodelay(true);
340+ /// app.listen("127.0.0.1:8080").await?;
341+ /// #
342+ /// # Ok(()) }) }
343+ /// ```
344+ pub fn set_tcp_nodelay ( & mut self , tcp_nodelay : bool ) -> & mut Self {
345+ self . tcp_nodelay = tcp_nodelay;
346+ self
347+ }
320348}
321349
322350impl < State : Send + Sync + ' static > std:: fmt:: Debug for Server < State > {
@@ -331,6 +359,7 @@ impl<State: Clone> Clone for Server<State> {
331359 router : self . router . clone ( ) ,
332360 state : self . state . clone ( ) ,
333361 middleware : self . middleware . clone ( ) ,
362+ tcp_nodelay : self . tcp_nodelay ,
334363 }
335364 }
336365}
0 commit comments