http gzip compression
This commit is contained in:
		| @@ -31,6 +31,7 @@ int main(int argc, char** argv) | ||||
|     bool followRedirects = false; | ||||
|     bool verbose = false; | ||||
|     bool save = false; | ||||
|     bool compress = false; | ||||
|     int port = 8080; | ||||
|     int connectTimeOutSeconds = 3; | ||||
|  | ||||
| @@ -71,6 +72,7 @@ int main(int argc, char** argv) | ||||
|     httpClientApp->add_flag("-L", followRedirects, "Header"); | ||||
|     httpClientApp->add_flag("-v", verbose, "Verbose"); | ||||
|     httpClientApp->add_flag("-O", save, "Save to disk"); | ||||
|     httpClientApp->add_flag("--compress", compress, "gzip compression"); | ||||
|     httpClientApp->add_option("--connect-timeout", connectTimeOutSeconds, "Connection timeout"); | ||||
|  | ||||
|     CLI11_PARSE(app, argc, argv); | ||||
| @@ -114,7 +116,8 @@ int main(int argc, char** argv) | ||||
|     { | ||||
|         return ix::ws_http_client_main(url, headers, data, | ||||
|                                        headersOnly, connectTimeOutSeconds, | ||||
|                                        followRedirects, verbose, save, output); | ||||
|                                        followRedirects, verbose, save, output, | ||||
|                                        compress); | ||||
|     } | ||||
|  | ||||
|     return 1; | ||||
|   | ||||
							
								
								
									
										3
									
								
								ws/ws.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								ws/ws.h
									
									
									
									
									
								
							| @@ -17,7 +17,8 @@ namespace ix | ||||
|                             bool followRedirects, | ||||
|                             bool verbose, | ||||
|                             bool save, | ||||
|                             const std::string& output); | ||||
|                             const std::string& output, | ||||
|                             bool compress); | ||||
|  | ||||
|     int ws_ping_pong_main(const std::string& url); | ||||
|  | ||||
|   | ||||
| @@ -90,7 +90,8 @@ namespace ix | ||||
|                             bool followRedirects, | ||||
|                             bool verbose, | ||||
|                             bool save, | ||||
|                             const std::string& output) | ||||
|                             const std::string& output, | ||||
|                             bool compress) | ||||
|     { | ||||
|         HttpRequestArgs args; | ||||
|         args.url = url; | ||||
| @@ -98,6 +99,7 @@ namespace ix | ||||
|         args.timeoutSecs = timeoutSecs; | ||||
|         args.followRedirects = followRedirects; | ||||
|         args.verbose = verbose; | ||||
|         args.compress = compress; | ||||
|  | ||||
|         HttpParameters httpParameters = parsePostParameters(data); | ||||
|  | ||||
| @@ -127,24 +129,13 @@ namespace ix | ||||
|         } | ||||
|  | ||||
|         std::cerr << "error code: " << errorCode << std::endl; | ||||
|         if (!errorMsg.empty()) | ||||
|         if (errorCode != 200) | ||||
|         { | ||||
|             std::cerr << "error message: " << errorMsg << std::endl; | ||||
|         } | ||||
|  | ||||
|         if (!headersOnly && errorCode == 200) | ||||
|         { | ||||
|             if (responseHeaders["Content-Type"] != "application/octet-stream") | ||||
|             { | ||||
|                 std::cout << "payload: " << payload << std::endl; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 std::cerr << "Binary output can mess up your terminal." << std::endl; | ||||
|                 std::cerr << "Use the -O flag to save the file to disk." << std::endl; | ||||
|                 std::cerr << "You can also use the --output option to specify a filename." << std::endl; | ||||
|             } | ||||
|  | ||||
|             if (save || !output.empty()) | ||||
|             { | ||||
|                 // FIMXE we should decode the url first | ||||
| @@ -159,6 +150,19 @@ namespace ix | ||||
|                 out.write((char*)&payload.front(), payload.size()); | ||||
|                 out.close(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (responseHeaders["Content-Type"] != "application/octet-stream") | ||||
|                 { | ||||
|                     std::cout << "payload: " << payload << std::endl; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     std::cerr << "Binary output can mess up your terminal." << std::endl; | ||||
|                     std::cerr << "Use the -O flag to save the file to disk." << std::endl; | ||||
|                     std::cerr << "You can also use the --output option to specify a filename." << std::endl; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user