-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_main.cc
51 lines (43 loc) · 1.43 KB
/
get_main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// EZ-HTTPS Copyright 2023 Jim Rogers (jimrogerz@gmail.com).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "https.h"
ABSL_FLAG(std::string, server, "", "Server to connect to");
ABSL_FLAG(std::string, path_and_query, "", "Path and query to request");
/**
* Performs a GET request.
*
* Example usage:
*
* bazel run :get_main -- --server="google.com" \
* --path_and_query="/search?q=ez-https"
*/
int main(int argc, char **argv) {
absl::ParseCommandLine(argc, argv);
Https https(absl::GetFlag(FLAGS_server));
auto status = https.Connect();
if (!status.ok()) {
std::cerr << status << std::endl;
return 1;
}
auto response = https.SetPath(absl::GetFlag(FLAGS_path_and_query)).Get();
if (!response.ok()) {
std::cerr << response.status() << std::endl;
return 1;
}
https.Close();
std::cout << response->body() << std::endl;
return 0;
}