Repository: actix/actix-web
File: actix-http/src/h2/service.rs (Rust)

Code before:
    use actix_tls::accept::TlsError;
    use std::io;

    impl<S, B> H2Service<TlsStream<TcpStream>, S, B>
    where
        S: ServiceFactory<Request, Config = ()>,
        S::Future: 'static,
        S::Error: Into<Error> + 'static,
        S::Response: Into<Response<B>> + 'static,
        <S::Service as Service<Request>>::Future: 'static,

        B: MessageBody + 'static,
        B::Error: Into<Error>,
    {
        /// Create Rustls based service
        pub fn rustls(
            self,
            mut config: ServerConfig,
        ) -> impl ServiceFactory<
            TcpStream,
            Config = (),
            Response = (),
            Error = TlsError<io::Error, DispatchError>,
            InitError = S::InitError,
        > {
            let mut protos = vec!["h2".to_string().into()];
            protos.extend_from_slice(&config.alpn_protocols);
            config.set_protocols(&protos);

            Acceptor::new(config)
                .map_err(TlsError::Tls)
                .map_init_err(|_| panic!())
                .and_then(fn_factory(|| {
                    ready(Ok::<_, S::InitError>(fn_service(
                        |io: TlsStream<TcpStream>| {
                            let peer_addr = io.get_ref().0.peer_addr().ok();
                            ready(Ok((io, peer_addr)))
                        },
                    )))
                }))
                .and_then(self.map_err(TlsError::Service))
        }
    }
}

impl<T, S, B> ServiceFactory<(T, Option<net::SocketAddr>)> for H2Service<T, S, B>
where
    T: AsyncRead + AsyncWrite + Unpin + 'static,

    S: ServiceFactory<Request, Config = ()>,
    S::Future: 'static,

Review comment (suggestion):
```suggestion
            let mut protos = vec![b"h2".to_vec()];
```

Code after:
    use actix_tls::accept::TlsError;
    use std::io;

    impl<S, B> H2Service<TlsStream<TcpStream>, S, B>
    where
        S: ServiceFactory<Request, Config = ()>,
        S::Future: 'static,
        S::Error: Into<Error> + 'static,
        S::Response: Into<Response<B>> + 'static,
        <S::Service as Service<Request>>::Future: 'static,

        B: MessageBody + 'static,
        B::Error: Into<Error>,
    {
        /// Create Rustls based service
        pub fn rustls(
            self,
            mut config: ServerConfig,
        ) -> impl ServiceFactory<
            TcpStream,
            Config = (),
            Response = (),
            Error = TlsError<io::Error, DispatchError>,
            InitError = S::InitError,
        > {
            let mut protos = vec![b"h2".to_vec()];
            protos.extend_from_slice(&config.alpn_protocols);
            config.set_protocols(&protos);

            Acceptor::new(config)
                .map_err(TlsError::Tls)
                .map_init_err(|_| panic!())
                .and_then(fn_factory(|| {
                    ready(Ok::<_, S::InitError>(fn_service(
                        |io: TlsStream<TcpStream>| {
                            let peer_addr = io.get_ref().0.peer_addr().ok();
                            ready(Ok((io, peer_addr)))
                        },
                    )))
                }))
                .and_then(self.map_err(TlsError::Service))
        }
    }
}

impl<T, S, B> ServiceFactory<(T, Option<net::SocketAddr>)> for H2Service<T, S, B>
where
    T: AsyncRead + AsyncWrite + Unpin + 'static,

    S: ServiceFactory<Request, Config = ()>,
    S::Future: 'static,