@@ -65,7 +65,7 @@ pub struct ClientBuilder {
6565 headers : HeaderMap ,
6666 reconnect_opts : ReconnectOptions ,
6767 read_timeout : Option < Duration > ,
68- last_event_id : String ,
68+ last_event_id : Option < String > ,
6969 method : String ,
7070 body : Option < String > ,
7171}
@@ -86,7 +86,7 @@ impl ClientBuilder {
8686 headers : header_map,
8787 reconnect_opts : ReconnectOptions :: default ( ) ,
8888 read_timeout : None ,
89- last_event_id : String :: new ( ) ,
89+ last_event_id : None ,
9090 method : String :: from ( "GET" ) ,
9191 body : None ,
9292 } )
@@ -107,7 +107,7 @@ impl ClientBuilder {
107107 /// Set the last event id for a stream when it is created. If it is set, it will be sent to the
108108 /// server in case it can replay missed events.
109109 pub fn last_event_id ( mut self , last_event_id : String ) -> ClientBuilder {
110- self . last_event_id = last_event_id;
110+ self . last_event_id = Some ( last_event_id) ;
111111 self
112112 }
113113
@@ -209,7 +209,7 @@ struct RequestProps {
209209struct ClientImpl < C > {
210210 http : hyper:: Client < C > ,
211211 request_props : RequestProps ,
212- last_event_id : String ,
212+ last_event_id : Option < String > ,
213213}
214214
215215impl < C > Client for ClientImpl < C >
@@ -274,14 +274,14 @@ pub struct ReconnectingRequest<C> {
274274 state : State ,
275275 next_reconnect_delay : Duration ,
276276 event_parser : EventParser ,
277- last_event_id : String ,
277+ last_event_id : Option < String > ,
278278}
279279
280280impl < C > ReconnectingRequest < C > {
281281 fn new (
282282 http : hyper:: Client < C > ,
283283 props : RequestProps ,
284- last_event_id : String ,
284+ last_event_id : Option < String > ,
285285 ) -> ReconnectingRequest < C > {
286286 let reconnect_delay = props. reconnect_opts . delay ;
287287 ReconnectingRequest {
@@ -306,11 +306,11 @@ impl<C> ReconnectingRequest<C> {
306306 request_builder = request_builder. header ( name, value) ;
307307 }
308308
309- if ! self . last_event_id . is_empty ( ) {
310- request_builder = request_builder . header (
311- "last-event-id" ,
312- HeaderValue :: from_str ( & self . last_event_id . clone ( ) ) . unwrap ( ) ,
313- ) ;
309+ if self . last_event_id . is_some ( ) {
310+ let id_as_header = HeaderValue :: from_str ( self . last_event_id . as_ref ( ) . unwrap ( ) )
311+ . map_err ( |e| Error :: InvalidParameter ( Box :: new ( e ) ) ) ? ;
312+
313+ request_builder = request_builder . header ( "last-event-id" , id_as_header ) ;
314314 }
315315
316316 let body = match & self . props . body {
@@ -357,8 +357,8 @@ where
357357 if let Some ( event) = this. event_parser . get_event ( ) {
358358 return match event {
359359 SSE :: Event ( ref evt) => {
360- if ! evt. id . is_empty ( ) {
361- * this. last_event_id = String :: from_utf8 ( evt. id . clone ( ) ) . unwrap ( ) ;
360+ if evt. id . is_some ( ) {
361+ * this. last_event_id = evt. id . clone ( ) ;
362362 }
363363
364364 if let Some ( retry) = evt. retry {
0 commit comments