@@ -45,6 +45,19 @@ impl Display for HeadersMismatchError {
45
45
}
46
46
}
47
47
48
+ #[ cfg( feature = "defmt" ) ]
49
+ impl defmt:: Format for HeadersMismatchError {
50
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
51
+ match self {
52
+ Self :: ResponseConnectionTypeMismatchError => defmt:: write!(
53
+ f,
54
+ "Response connection type is different from the request connection type"
55
+ ) ,
56
+ Self :: BodyTypeError ( s) => defmt:: write!( f, "Body type mismatch: {}" , s) ,
57
+ }
58
+ }
59
+ }
60
+
48
61
/// Http methods
49
62
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
50
63
#[ cfg_attr( feature = "std" , derive( Hash ) ) ]
@@ -202,6 +215,13 @@ impl Display for Method {
202
215
}
203
216
}
204
217
218
+ #[ cfg( feature = "defmt" ) ]
219
+ impl defmt:: Format for Method {
220
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
221
+ defmt:: write!( f, "{}" , self . as_str( ) )
222
+ }
223
+ }
224
+
205
225
/// HTTP headers
206
226
#[ derive( Debug ) ]
207
227
pub struct Headers < ' b , const N : usize = 64 > ( [ httparse:: Header < ' b > ; N ] ) ;
@@ -565,6 +585,17 @@ impl Display for ConnectionType {
565
585
}
566
586
}
567
587
588
+ #[ cfg( feature = "defmt" ) ]
589
+ impl defmt:: Format for ConnectionType {
590
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
591
+ match self {
592
+ Self :: KeepAlive => defmt:: write!( f, "Keep-Alive" ) ,
593
+ Self :: Close => defmt:: write!( f, "Close" ) ,
594
+ Self :: Upgrade => defmt:: write!( f, "Upgrade" ) ,
595
+ }
596
+ }
597
+ }
598
+
568
599
/// Body type
569
600
#[ derive( Copy , Clone , Eq , PartialEq , Hash , Debug ) ]
570
601
pub enum BodyType {
@@ -734,6 +765,17 @@ impl Display for BodyType {
734
765
}
735
766
}
736
767
768
+ #[ cfg( feature = "defmt" ) ]
769
+ impl defmt:: Format for BodyType {
770
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
771
+ match self {
772
+ Self :: Chunked => defmt:: write!( f, "Chunked" ) ,
773
+ Self :: ContentLen ( len) => defmt:: write!( f, "Content-Length: {}" , len) ,
774
+ Self :: Raw => defmt:: write!( f, "Raw" ) ,
775
+ }
776
+ }
777
+ }
778
+
737
779
/// Request headers including the request line (method, path)
738
780
#[ derive( Debug ) ]
739
781
pub struct RequestHeaders < ' b , const N : usize > {
@@ -790,6 +832,23 @@ impl<const N: usize> Display for RequestHeaders<'_, N> {
790
832
}
791
833
}
792
834
835
+ #[ cfg( feature = "defmt" ) ]
836
+ impl < const N : usize > defmt:: Format for RequestHeaders < ' _ , N > {
837
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
838
+ defmt:: write!( f, "{} " , if self . http11 { "HTTP/1.1" } else { "HTTP/1.0" } ) ;
839
+
840
+ defmt:: write!( f, "{} {}\n " , self . method, self . path) ;
841
+
842
+ for ( name, value) in self . headers . iter ( ) {
843
+ if name. is_empty ( ) {
844
+ break ;
845
+ }
846
+
847
+ defmt:: write!( f, "{}: {}\n " , name, value) ;
848
+ }
849
+ }
850
+ }
851
+
793
852
/// Response headers including the response line (HTTP version, status code, reason phrase)
794
853
#[ derive( Debug ) ]
795
854
pub struct ResponseHeaders < ' b , const N : usize > {
@@ -851,6 +910,23 @@ impl<const N: usize> Display for ResponseHeaders<'_, N> {
851
910
}
852
911
}
853
912
913
+ #[ cfg( feature = "defmt" ) ]
914
+ impl < const N : usize > defmt:: Format for ResponseHeaders < ' _ , N > {
915
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
916
+ defmt:: write!( f, "{} " , if self . http11 { "HTTP/1.1 " } else { "HTTP/1.0" } ) ;
917
+
918
+ defmt:: write!( f, "{} {}\n " , self . code, self . reason. unwrap_or( "" ) ) ;
919
+
920
+ for ( name, value) in self . headers . iter ( ) {
921
+ if name. is_empty ( ) {
922
+ break ;
923
+ }
924
+
925
+ defmt:: write!( f, "{}: {}\n " , name, value) ;
926
+ }
927
+ }
928
+ }
929
+
854
930
/// Websocket utilities
855
931
pub mod ws {
856
932
use crate :: Method ;
@@ -935,6 +1011,17 @@ pub mod ws {
935
1011
}
936
1012
}
937
1013
1014
+ #[ cfg( feature = "defmt" ) ]
1015
+ impl defmt:: Format for UpgradeError {
1016
+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
1017
+ match self {
1018
+ Self :: NoVersion => defmt:: write!( f, "No Sec-WebSocket-Version header" ) ,
1019
+ Self :: NoSecKey => defmt:: write!( f, "No Sec-WebSocket-Key header" ) ,
1020
+ Self :: UnsupportedVersion => defmt:: write!( f, "Unsupported Sec-WebSocket-Version" ) ,
1021
+ }
1022
+ }
1023
+ }
1024
+
938
1025
#[ cfg( feature = "std" ) ]
939
1026
impl std:: error:: Error for UpgradeError { }
940
1027
0 commit comments