Remove http prefix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "webcc/http_client_session.h"
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN64))
|
||||
@@ -19,7 +19,7 @@ static void PrintSeparator() {
|
||||
int main() {
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
webcc::HttpClientSession session;
|
||||
webcc::ClientSession session;
|
||||
|
||||
session.set_ssl_verify(kSslVerify);
|
||||
|
||||
@@ -27,7 +27,7 @@ int main() {
|
||||
PrintSeparator();
|
||||
|
||||
// Using request builder:
|
||||
auto r = session.Request(webcc::HttpRequestBuilder{}.Get().
|
||||
auto r = session.Request(webcc::RequestBuilder{}.Get().
|
||||
Url("http://httpbin.org/get").
|
||||
Query("key1", "value1").
|
||||
Query("key2", "value2").
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "webcc/http_client_session.h"
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN64))
|
||||
@@ -47,12 +47,12 @@ int main(int argc, char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
webcc::HttpClientSession session;
|
||||
webcc::ClientSession session;
|
||||
|
||||
try {
|
||||
//auto r = session.PostFile(url, "file", upload_dir / "remember.txt");
|
||||
|
||||
auto r = session.Request(webcc::HttpRequestBuilder{}.Post().
|
||||
auto r = session.Request(webcc::RequestBuilder{}.Post().
|
||||
Url(url).
|
||||
File("file", upload_dir / "remember.txt").
|
||||
Form("json", "{}", "application/json")
|
||||
|
||||
@@ -20,9 +20,9 @@ public:
|
||||
}
|
||||
|
||||
response->content = "OK";
|
||||
response->media_type = webcc::http::media_types::kTextPlain;
|
||||
response->media_type = webcc::media_types::kTextPlain;
|
||||
response->charset = "utf-8";
|
||||
response->status = webcc::http::Status::kCreated;
|
||||
response->status = webcc::Status::kCreated;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+15
-11
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "webcc/http_client_session.h"
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -61,7 +61,7 @@ void PrettyPrintJsonString(const std::string& str) {
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// List public events.
|
||||
void ListEvents(webcc::HttpClientSession& session) {
|
||||
void ListEvents(webcc::ClientSession& session) {
|
||||
try {
|
||||
auto r = session.Get(kUrlRoot + "/events");
|
||||
|
||||
@@ -75,8 +75,7 @@ void ListEvents(webcc::HttpClientSession& session) {
|
||||
// List the followers of the given user.
|
||||
// Example:
|
||||
// ListUserFollowers(session, "<login>")
|
||||
void ListUserFollowers(webcc::HttpClientSession& session,
|
||||
const std::string& user) {
|
||||
void ListUserFollowers(webcc::ClientSession& session, const std::string& user) {
|
||||
try {
|
||||
auto r = session.Get(kUrlRoot + "/users/" + user + "/followers");
|
||||
|
||||
@@ -90,11 +89,11 @@ void ListUserFollowers(webcc::HttpClientSession& session,
|
||||
// List the followers of the current authorized user using Basic authorization.
|
||||
// E.g., list my own followers:
|
||||
// ListAuthUserFollowers(session, "sprinfall@gmail.com", "<MyPassword>");
|
||||
void ListAuthUserFollowers(webcc::HttpClientSession& session,
|
||||
void ListAuthUserFollowers(webcc::ClientSession& session,
|
||||
const std::string& login,
|
||||
const std::string& password) {
|
||||
try {
|
||||
auto r = session.Request(webcc::HttpRequestBuilder{}.Get().
|
||||
auto r = session.Request(webcc::RequestBuilder{}.Get().
|
||||
Url(kUrlRoot + "/user/followers").
|
||||
AuthBasic(login, password)
|
||||
());
|
||||
@@ -106,8 +105,9 @@ void ListAuthUserFollowers(webcc::HttpClientSession& session,
|
||||
}
|
||||
}
|
||||
|
||||
void CreateAuthorization(webcc::HttpClientSession& session,
|
||||
const std::string& auth) {
|
||||
void CreateAuthorization(webcc::ClientSession& session,
|
||||
const std::string& login,
|
||||
const std::string& password) {
|
||||
try {
|
||||
std::string data =
|
||||
"{\n"
|
||||
@@ -115,8 +115,12 @@ void CreateAuthorization(webcc::HttpClientSession& session,
|
||||
" 'scopes': ['public_repo', 'repo', 'repo:status', 'user']\n"
|
||||
"}";
|
||||
|
||||
auto r = session.Post(kUrlRoot + "/authorizations", std::move(data), true,
|
||||
{"Authorization", auth});
|
||||
auto r = session.Request(webcc::RequestBuilder{}.Post().
|
||||
Url(kUrlRoot + "/authorizations").
|
||||
Data(std::move(data)).
|
||||
Json(true).
|
||||
AuthBasic(login, password)
|
||||
());
|
||||
|
||||
std::cout << r->content() << std::endl;
|
||||
|
||||
@@ -130,7 +134,7 @@ void CreateAuthorization(webcc::HttpClientSession& session,
|
||||
int main() {
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
webcc::HttpClientSession session;
|
||||
webcc::ClientSession session;
|
||||
|
||||
session.set_ssl_verify(kSslVerify);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "webcc/http_client_session.h"
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
#include "examples/common/book.h"
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
class BookClientBase {
|
||||
public:
|
||||
BookClientBase(webcc::HttpClientSession& session, const std::string& url)
|
||||
BookClientBase(webcc::ClientSession& session, const std::string& url)
|
||||
: session_(session), url_(url) {
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
protected:
|
||||
// Check HTTP response status.
|
||||
bool CheckStatus(webcc::HttpResponsePtr response, int expected_status) {
|
||||
bool CheckStatus(webcc::ResponsePtr response, int expected_status) {
|
||||
int status = response->status();
|
||||
if (status != expected_status) {
|
||||
LOG_ERRO("HTTP status error (actual: %d, expected: %d).",
|
||||
@@ -42,14 +42,14 @@ protected:
|
||||
protected:
|
||||
std::string url_;
|
||||
|
||||
webcc::HttpClientSession& session_;
|
||||
webcc::ClientSession& session_;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BookListClient : public BookClientBase {
|
||||
public:
|
||||
BookListClient(webcc::HttpClientSession& session, const std::string& url)
|
||||
BookListClient(webcc::ClientSession& session, const std::string& url)
|
||||
: BookClientBase(session, url) {
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
try {
|
||||
auto r = session_.Get(url_ + "/books");
|
||||
|
||||
if (!CheckStatus(r, webcc::http::Status::kOK)) {
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
// Response HTTP status error.
|
||||
return false;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
try {
|
||||
auto r = session_.Post(url_ + "/books", JsonToString(req_json), true);
|
||||
|
||||
if (!CheckStatus(r, webcc::http::Status::kCreated)) {
|
||||
if (!CheckStatus(r, webcc::Status::kCreated)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
|
||||
class BookDetailClient : public BookClientBase {
|
||||
public:
|
||||
BookDetailClient(webcc::HttpClientSession& session, const std::string& url)
|
||||
BookDetailClient(webcc::ClientSession& session, const std::string& url)
|
||||
: BookClientBase(session, url) {
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
try {
|
||||
auto r = session_.Get(url_ + "/books/" + id);
|
||||
|
||||
if (!CheckStatus(r, webcc::http::Status::kOK)) {
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
try {
|
||||
auto r = session_.Put(url_ + "/books/" + id, JsonToString(json), true);
|
||||
|
||||
if (!CheckStatus(r, webcc::http::Status::kOK)) {
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
try {
|
||||
auto r = session_.Delete(url_ + "/books/" + id);
|
||||
|
||||
if (!CheckStatus(r, webcc::http::Status::kOK)) {
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ int main(int argc, char* argv[]) {
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE_FILE_OVERWRITE);
|
||||
|
||||
// Share the same session.
|
||||
webcc::HttpClientSession session;
|
||||
webcc::ClientSession session;
|
||||
|
||||
// Session-level settings.
|
||||
session.set_timeout(timeout);
|
||||
|
||||
@@ -100,9 +100,9 @@ void BookListService::Get(const webcc::UrlQuery& /*query*/,
|
||||
|
||||
// TODO: Simplify
|
||||
response->content = JsonToString(json);
|
||||
response->media_type = webcc::http::media_types::kApplicationJson;
|
||||
response->media_type = webcc::media_types::kApplicationJson;
|
||||
response->charset = "utf-8";
|
||||
response->status = webcc::http::Status::kOK;
|
||||
response->status = webcc::Status::kOK;
|
||||
}
|
||||
|
||||
void BookListService::Post(const std::string& request_content,
|
||||
@@ -117,12 +117,12 @@ void BookListService::Post(const std::string& request_content,
|
||||
json["id"] = id;
|
||||
|
||||
response->content = JsonToString(json);
|
||||
response->media_type = webcc::http::media_types::kApplicationJson;
|
||||
response->media_type = webcc::media_types::kApplicationJson;
|
||||
response->charset = "utf-8";
|
||||
response->status = webcc::http::Status::kCreated;
|
||||
response->status = webcc::Status::kCreated;
|
||||
} else {
|
||||
// Invalid JSON
|
||||
response->status = webcc::http::Status::kBadRequest;
|
||||
response->status = webcc::Status::kBadRequest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ void BookDetailService::Get(const webcc::UrlMatches& url_matches,
|
||||
if (url_matches.size() != 1) {
|
||||
// Using kNotFound means the resource specified by the URL cannot be found.
|
||||
// kBadRequest could be another choice.
|
||||
response->status = webcc::http::Status::kNotFound;
|
||||
response->status = webcc::Status::kNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -144,14 +144,14 @@ void BookDetailService::Get(const webcc::UrlMatches& url_matches,
|
||||
|
||||
const Book& book = g_book_store.GetBook(book_id);
|
||||
if (book.IsNull()) {
|
||||
response->status = webcc::http::Status::kNotFound;
|
||||
response->status = webcc::Status::kNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
response->content = BookToJsonString(book);
|
||||
response->media_type = webcc::http::media_types::kApplicationJson;
|
||||
response->media_type = webcc::media_types::kApplicationJson;
|
||||
response->charset = "utf-8";
|
||||
response->status = webcc::http::Status::kOK;
|
||||
response->status = webcc::Status::kOK;
|
||||
}
|
||||
|
||||
void BookDetailService::Put(const webcc::UrlMatches& url_matches,
|
||||
@@ -160,7 +160,7 @@ void BookDetailService::Put(const webcc::UrlMatches& url_matches,
|
||||
Sleep(sleep_seconds_);
|
||||
|
||||
if (url_matches.size() != 1) {
|
||||
response->status = webcc::http::Status::kNotFound;
|
||||
response->status = webcc::Status::kNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,14 +168,14 @@ void BookDetailService::Put(const webcc::UrlMatches& url_matches,
|
||||
|
||||
Book book;
|
||||
if (!JsonStringToBook(request_content, &book)) {
|
||||
response->status = webcc::http::Status::kBadRequest;
|
||||
response->status = webcc::Status::kBadRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
book.id = book_id;
|
||||
g_book_store.UpdateBook(book);
|
||||
|
||||
response->status = webcc::http::Status::kOK;
|
||||
response->status = webcc::Status::kOK;
|
||||
}
|
||||
|
||||
void BookDetailService::Delete(const webcc::UrlMatches& url_matches,
|
||||
@@ -183,18 +183,18 @@ void BookDetailService::Delete(const webcc::UrlMatches& url_matches,
|
||||
Sleep(sleep_seconds_);
|
||||
|
||||
if (url_matches.size() != 1) {
|
||||
response->status = webcc::http::Status::kNotFound;
|
||||
response->status = webcc::Status::kNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string& book_id = url_matches[0];
|
||||
|
||||
if (!g_book_store.DeleteBook(book_id)) {
|
||||
response->status = webcc::http::Status::kNotFound;
|
||||
response->status = webcc::Status::kNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
response->status = webcc::http::Status::kOK;
|
||||
response->status = webcc::Status::kOK;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user