11use std:: future:: Future ;
22
33use vetis:: {
4- config:: { ListenerConfig , SecurityConfig , ServerConfig , VirtualHostConfig } ,
4+ config:: { ListenerConfig , Protocol , SecurityConfig , ServerConfig , VirtualHostConfig } ,
55 errors:: VetisError ,
66 server:: {
77 path:: HandlerPath ,
@@ -21,6 +21,7 @@ use crate::{
2121pub struct VetisAdapterConfigBuilder {
2222 hostname : Option < String > ,
2323 interface : String ,
24+ protocol : Protocol ,
2425 port : u16 ,
2526 cert : Option < Vec < u8 > > ,
2627 key : Option < Vec < u8 > > ,
@@ -52,6 +53,18 @@ impl VetisAdapterConfigBuilder {
5253 self
5354 }
5455
56+ /// Sets the protocol for the server.
57+ ///
58+ /// # Arguments
59+ /// * `protocol` - The protocol to set.
60+ ///
61+ /// # Returns
62+ /// A new `VetisAdapterConfigBuilder` instance with the protocol set.
63+ pub fn protocol ( mut self , protocol : Protocol ) -> Self {
64+ self . protocol = protocol;
65+ self
66+ }
67+
5568 /// Sets the port for the server.
5669 ///
5770 /// # Arguments
@@ -108,6 +121,7 @@ impl VetisAdapterConfigBuilder {
108121 VetisAdapterConfig {
109122 hostname : self . hostname ,
110123 interface : self . interface ,
124+ protocol : self . protocol ,
111125 port : self . port ,
112126 cert : self . cert ,
113127 key : self . key ,
@@ -121,6 +135,7 @@ impl VetisAdapterConfigBuilder {
121135pub struct VetisAdapterConfig {
122136 hostname : Option < String > ,
123137 interface : String ,
138+ protocol : Protocol ,
124139 port : u16 ,
125140 cert : Option < Vec < u8 > > ,
126141 key : Option < Vec < u8 > > ,
@@ -141,6 +156,7 @@ impl Default for VetisAdapterConfig {
141156 Self {
142157 hostname : None ,
143158 interface : "0.0.0.0" . into ( ) ,
159+ protocol : Protocol :: Http1 ,
144160 port : 80 ,
145161 cert : None ,
146162 key : None ,
@@ -163,6 +179,7 @@ impl VetisAdapterConfig {
163179 VetisAdapterConfigBuilder {
164180 hostname : None ,
165181 interface : "0.0.0.0" . into ( ) ,
182+ protocol : Protocol :: Http1 ,
166183 port : 80 ,
167184 cert : None ,
168185 key : None ,
@@ -223,11 +240,14 @@ impl From<VetisAdapterConfig> for ServerConfig {
223240 fn from ( config : VetisAdapterConfig ) -> Self {
224241 let listener_config = ListenerConfig :: builder ( )
225242 . interface ( & config. interface )
243+ . protocol ( config. protocol )
226244 . port ( config. port )
227- . build ( ) ;
245+ . build ( )
246+ . expect ( "Failed to build listener config" ) ;
228247 ServerConfig :: builder ( )
229248 . add_listener ( listener_config)
230249 . build ( )
250+ . expect ( "Failed to build server config" )
231251 }
232252}
233253
@@ -353,6 +373,7 @@ impl ServerAdapter for VetisAdapter {
353373
354374 let host_config = VirtualHostConfig :: builder ( )
355375 . hostname ( & hostname)
376+ . root_directory ( "src/tests" )
356377 . port ( self . config . port ( ) ) ;
357378
358379 let host_config = if let Some ( ( ( cert, key) , ca) ) = self
@@ -374,7 +395,8 @@ impl ServerAdapter for VetisAdapter {
374395 . cert_from_bytes ( cert. clone ( ) )
375396 . key_from_bytes ( key. clone ( ) )
376397 . ca_cert_from_bytes ( ca. clone ( ) )
377- . build ( ) ,
398+ . build ( )
399+ . map_err ( |e| EasyHttpMockError :: Server ( ServerError :: Config ( e. to_string ( ) ) ) ) ?,
378400 )
379401 } else {
380402 host_config
0 commit comments