@@ -26,6 +26,16 @@ pub enum TEdgeHttpCli {
2626 #[ command( flatten) ]
2727 content : Content ,
2828
29+ /// MIME type of the content
30+ #[ clap( long, default_value = "application/json" ) ]
31+ #[ arg( value_parser = parse_mime_type) ]
32+ content_type : String ,
33+
34+ /// MIME type of the expected content
35+ #[ clap( long, default_value = "application/json" ) ]
36+ #[ arg( value_parser = parse_mime_type) ]
37+ accept_type : String ,
38+
2939 /// Optional c8y cloud profile
3040 #[ clap( long) ]
3141 profile : Option < ProfileName > ,
@@ -40,6 +50,11 @@ pub enum TEdgeHttpCli {
4050 #[ command( flatten) ]
4151 content : Content ,
4252
53+ /// MIME type of the content
54+ #[ clap( long, default_value = "application/json" ) ]
55+ #[ arg( value_parser = parse_mime_type) ]
56+ content_type : String ,
57+
4358 /// Optional c8y cloud profile
4459 #[ clap( long) ]
4560 profile : Option < ProfileName > ,
@@ -50,6 +65,11 @@ pub enum TEdgeHttpCli {
5065 /// Source URI
5166 uri : String ,
5267
68+ /// MIME type of the expected content
69+ #[ clap( long, default_value = "application/json" ) ]
70+ #[ arg( value_parser = parse_mime_type) ]
71+ accept_type : String ,
72+
5373 /// Optional c8y cloud profile
5474 #[ clap( long) ]
5575 profile : Option < ProfileName > ,
@@ -82,6 +102,10 @@ pub struct Content {
82102 file : Option < Utf8PathBuf > ,
83103}
84104
105+ fn parse_mime_type ( input : & str ) -> Result < String , Error > {
106+ Ok ( input. parse :: < mime_guess:: mime:: Mime > ( ) ?. to_string ( ) )
107+ }
108+
85109impl TryFrom < Content > for blocking:: Body {
86110 type Error = std:: io:: Error ;
87111
@@ -121,13 +145,7 @@ impl BuildCommand for TEdgeHttpCli {
121145 let url = format ! ( "{protocol}://{host}:{port}{uri}" ) ;
122146 let identity = config. http . client . auth . identity ( ) ?;
123147 let client = http_client ( config. cloud_root_certs ( ) , identity. as_ref ( ) ) ?;
124-
125- let action = match self {
126- TEdgeHttpCli :: Post { content, .. } => HttpAction :: Post ( content) ,
127- TEdgeHttpCli :: Put { content, .. } => HttpAction :: Put ( content) ,
128- TEdgeHttpCli :: Get { .. } => HttpAction :: Get ,
129- TEdgeHttpCli :: Delete { .. } => HttpAction :: Delete ,
130- } ;
148+ let action = self . into ( ) ;
131149
132150 Ok ( HttpCommand {
133151 client,
@@ -138,6 +156,33 @@ impl BuildCommand for TEdgeHttpCli {
138156 }
139157}
140158
159+ impl From < TEdgeHttpCli > for HttpAction {
160+ fn from ( value : TEdgeHttpCli ) -> Self {
161+ match value {
162+ TEdgeHttpCli :: Post {
163+ content,
164+ content_type,
165+ accept_type,
166+ ..
167+ } => HttpAction :: Post {
168+ content,
169+ content_type,
170+ accept_type,
171+ } ,
172+ TEdgeHttpCli :: Put {
173+ content,
174+ content_type,
175+ ..
176+ } => HttpAction :: Put {
177+ content,
178+ content_type,
179+ } ,
180+ TEdgeHttpCli :: Get { accept_type, .. } => HttpAction :: Get { accept_type } ,
181+ TEdgeHttpCli :: Delete { .. } => HttpAction :: Delete ,
182+ }
183+ }
184+ }
185+
141186impl TEdgeHttpCli {
142187 fn uri ( & self ) -> & str {
143188 match self {
0 commit comments