1- using HttpClientToCurl . Config ;
1+ using System . Net . Http . Headers ;
2+ using HttpClientToCurl . Config ;
23using HttpClientToCurl . Utility ;
34
45namespace HttpClientToCurl ;
@@ -7,7 +8,11 @@ public static class Main
78{
89 #region :: EXTENSIONS ::
910
10- public static string GenerateCurlInString ( this HttpClient httpClient , HttpRequestMessage httpRequestMessage , string requestUri = null , Action < StringConfig > config = null )
11+ public static string GenerateCurlInString (
12+ this HttpClient httpClient ,
13+ HttpRequestMessage httpRequestMessage ,
14+ string requestUri = null ,
15+ Action < StringConfig > config = null )
1116 {
1217 var stringConfig = new StringConfig ( ) ;
1318 config ? . Invoke ( stringConfig ) ;
@@ -25,15 +30,73 @@ public static string GenerateCurlInString(this HttpClient httpClient, HttpReques
2530
2631 return script ;
2732 }
28-
29- public static void GenerateCurlInConsole ( this HttpClient httpClient , HttpRequestMessage httpRequestMessage , string requestUri = null , Action < ConsoleConfig > config = null )
33+
34+ public static string GenerateCurlInString (
35+ this HttpClient httpClient ,
36+ HttpMethod httpMethod ,
37+ string requestUri = null ,
38+ HttpRequestHeaders requestHeaders = null ,
39+ HttpContent requestBody = null ,
40+ Action < StringConfig > config = null )
41+ {
42+ var stringConfig = new StringConfig ( ) ;
43+ config ? . Invoke ( stringConfig ) ;
44+
45+ if ( ! stringConfig . TurnOn )
46+ return string . Empty ;
47+
48+ var httpRequestMessage = Helpers . FillHttpRequestMessage ( httpMethod , requestHeaders , requestBody ) ;
49+
50+ string script = Generator . GenerateCurl (
51+ httpClient ,
52+ httpRequestMessage ,
53+ string . IsNullOrWhiteSpace ( requestUri )
54+ ? httpRequestMessage . RequestUri ? . ToString ( )
55+ : requestUri ,
56+ stringConfig . NeedAddDefaultHeaders ) ;
57+
58+ return script ;
59+ }
60+
61+ public static void GenerateCurlInConsole (
62+ this HttpClient httpClient ,
63+ HttpRequestMessage httpRequestMessage ,
64+ string requestUri = null ,
65+ Action < ConsoleConfig > config = null )
66+ {
67+ var consoleConfig = new ConsoleConfig ( ) ;
68+ config ? . Invoke ( consoleConfig ) ;
69+
70+ if ( ! consoleConfig . TurnOn )
71+ return ;
72+
73+ string script = Generator . GenerateCurl (
74+ httpClient ,
75+ httpRequestMessage ,
76+ string . IsNullOrWhiteSpace ( requestUri )
77+ ? httpRequestMessage . RequestUri ? . ToString ( )
78+ : requestUri ,
79+ consoleConfig . NeedAddDefaultHeaders ) ;
80+
81+ Helpers . WriteInConsole ( script , consoleConfig . EnableCodeBeautification , httpRequestMessage . Method ) ;
82+ }
83+
84+ public static void GenerateCurlInConsole (
85+ this HttpClient httpClient ,
86+ HttpMethod httpMethod ,
87+ string requestUri = null ,
88+ HttpRequestHeaders requestHeaders = null ,
89+ HttpContent requestBody = null ,
90+ Action < ConsoleConfig > config = null )
3091 {
3192 var consoleConfig = new ConsoleConfig ( ) ;
3293 config ? . Invoke ( consoleConfig ) ;
3394
3495 if ( ! consoleConfig . TurnOn )
3596 return ;
3697
98+ var httpRequestMessage = Helpers . FillHttpRequestMessage ( httpMethod , requestHeaders , requestBody ) ;
99+
37100 string script = Generator . GenerateCurl (
38101 httpClient ,
39102 httpRequestMessage ,
@@ -45,7 +108,11 @@ public static void GenerateCurlInConsole(this HttpClient httpClient, HttpRequest
45108 Helpers . WriteInConsole ( script , consoleConfig . EnableCodeBeautification , httpRequestMessage . Method ) ;
46109 }
47110
48- public static void GenerateCurlInFile ( this HttpClient httpClient , HttpRequestMessage httpRequestMessage , string requestUri = null , Action < FileConfig > config = null )
111+ public static void GenerateCurlInFile (
112+ this HttpClient httpClient ,
113+ HttpRequestMessage httpRequestMessage ,
114+ string requestUri = null ,
115+ Action < FileConfig > config = null )
49116 {
50117 var fileConfig = new FileConfig ( ) ;
51118 config ? . Invoke ( fileConfig ) ;
@@ -64,5 +131,32 @@ public static void GenerateCurlInFile(this HttpClient httpClient, HttpRequestMes
64131 Helpers . WriteInFile ( script , fileConfig . Filename , fileConfig . Path ) ;
65132 }
66133
134+ public static void GenerateCurlInFile (
135+ this HttpClient httpClient ,
136+ HttpMethod httpMethod ,
137+ string requestUri = null ,
138+ HttpRequestHeaders requestHeaders = null ,
139+ HttpContent requestBody = null ,
140+ Action < FileConfig > config = null )
141+ {
142+ var fileConfig = new FileConfig ( ) ;
143+ config ? . Invoke ( fileConfig ) ;
144+
145+ if ( ! fileConfig . TurnOn )
146+ return ;
147+
148+ var httpRequestMessage = Helpers . FillHttpRequestMessage ( httpMethod , requestHeaders , requestBody ) ;
149+
150+ string script = Generator . GenerateCurl (
151+ httpClient ,
152+ httpRequestMessage ,
153+ string . IsNullOrWhiteSpace ( requestUri )
154+ ? httpRequestMessage . RequestUri ? . ToString ( )
155+ : requestUri ,
156+ fileConfig . NeedAddDefaultHeaders ) ;
157+
158+ Helpers . WriteInFile ( script , fileConfig . Filename , fileConfig . Path ) ;
159+ }
160+
67161 #endregion
68162}
0 commit comments