srctree

Robin Linden parent b89ee299 d37876a5
protocol: Give the http library a more suitable name

inlinesplit
.bazelrc added: 35, removed: 35, total 0
@@ -23,9 +23,9 @@ build:gnulike --copt='-fno-common'
build:gnulike --cxxopt='-Wnon-virtual-dtor'
build:gnulike --cxxopt='-Woverloaded-virtual'
build:gnulike --copt='-Wno-missing-field-initializers' # Common idiom for zeroing members.
build:gnulike --per_file_copt='http:get@-Wno-sign-compare' # asio leaks this into our code.
build:gnulike --per_file_copt='http:get@-Wno-undef' # asio leaks this into our code.
build:gnulike --per_file_copt='http:get@-Wno-shadow' # asio leaks this into our code.
build:gnulike --per_file_copt='protocol:get@-Wno-sign-compare' # asio leaks this into our code.
build:gnulike --per_file_copt='protocol:get@-Wno-undef' # asio leaks this into our code.
build:gnulike --per_file_copt='protocol:get@-Wno-shadow' # asio leaks this into our code.
build:gnulike --per_file_copt='external/asio[:/]@-Wno-sign-compare'
build:gnulike --per_file_copt='external/asio[:/]@-Wno-undef'
build:gnulike --per_file_copt='external/boringssl[:/]@-Wno-overlength-strings'
 
browser/BUILD added: 35, removed: 35, total 0
@@ -14,8 +14,8 @@ cc_binary(
}),
deps = [
"//html",
"//http",
"//layout",
"//protocol",
"//style",
"//tui",
"//uri",
@@ -30,8 +30,8 @@ cc_binary(
"//css",
"//dom",
"//html",
"//http",
"//layout",
"//protocol",
"//render",
"//style",
"//uri",
 
browser/gui.cpp added: 35, removed: 35, total 0
@@ -4,8 +4,8 @@
 
#include "css/parse.h"
#include "html/parse.h"
#include "http/get.h"
#include "layout/layout.h"
#include "protocol/get.h"
#include "render/render.h"
#include "style/style.h"
 
@@ -61,7 +61,7 @@ int main(int argc, char **argv) {
std::string url_buf{argc > 1 ? argv[1] : kDefaultUrl};
bool url_from_argv = argc > 1;
sf::Clock clock;
http::Response response{};
protocol::Response response{};
dom::Document dom{};
std::optional<style::StyledNode> styled{};
std::optional<layout::LayoutBox> layout{};
@@ -130,8 +130,8 @@ int main(int argc, char **argv) {
return status_code == 301 || status_code == 302;
};
 
response = http::get(*uri);
while (response.err == http::Error::Ok && is_redirect(response.status_line.status_code)) {
response = protocol::get(*uri);
while (response.err == protocol::Error::Ok && is_redirect(response.status_line.status_code)) {
spdlog::info("Following {} redirect from {} to {}",
response.status_line.status_code,
uri->uri,
@@ -141,18 +141,18 @@ int main(int argc, char **argv) {
if (uri->path.empty()) {
uri->path = "/";
}
response = http::get(*uri);
response = protocol::get(*uri);
}
 
status_line_str = fmt::format("{} {} {}",
response.status_line.version,
response.status_line.status_code,
response.status_line.reason);
response_headers_str = http::to_string(response.headers);
response_headers_str = protocol::to_string(response.headers);
dom_str.clear();
 
switch (response.err) {
case http::Error::Ok: {
case protocol::Error::Ok: {
dom = html::parse(response.body);
dom_str += dom::to_string(dom);
 
@@ -186,7 +186,7 @@ int main(int argc, char **argv) {
auto const &elem = std::get<dom::Element>(link->data);
auto stylesheet_url = fmt::format("{}{}", url_buf, elem.attributes.at("href"));
spdlog::info("Downloading stylesheet from {}", stylesheet_url);
auto style_data = http::get(*uri::Uri::parse(stylesheet_url));
auto style_data = protocol::get(*uri::Uri::parse(stylesheet_url));
 
auto new_rules = css::parse(style_data.body);
stylesheet.reserve(stylesheet.size() + new_rules.size());
@@ -201,17 +201,17 @@ int main(int argc, char **argv) {
layout_needed = true;
break;
}
case http::Error::Unresolved: {
case protocol::Error::Unresolved: {
err_str = fmt::format("Unable to resolve endpoint for '{}'", url_buf);
spdlog::error(err_str);
break;
}
case http::Error::Unhandled: {
case protocol::Error::Unhandled: {
err_str = fmt::format("Unhandled protocol for '{}'", url_buf);
spdlog::error(err_str);
break;
}
case http::Error::InvalidResponse: {
case protocol::Error::InvalidResponse: {
err_str = fmt::format("Invalid response from '{}'", url_buf);
spdlog::error(err_str);
break;
@@ -226,7 +226,7 @@ int main(int argc, char **argv) {
layout_needed = false;
}
 
if (response.err != http::Error::Ok) {
if (response.err != protocol::Error::Ok) {
ImGui::TextUnformatted(err_str.c_str());
}
ImGui::End();
 
browser/tui.cpp added: 35, removed: 35, total 0
@@ -4,8 +4,8 @@
 
#include "dom/dom.h"
#include "html/parse.h"
#include "http/get.h"
#include "layout/layout.h"
#include "protocol/get.h"
#include "style/style.h"
#include "tui/tui.h"
 
@@ -34,8 +34,8 @@ int main(int argc, char **argv) {
}
 
spdlog::info("Fetching HTML from {}", uri->uri);
auto response = http::get(*uri);
if (response.err != http::Error::Ok) {
auto response = protocol::get(*uri);
if (response.err != protocol::Error::Ok) {
spdlog::error("Got error {} from {}", response.err, uri->uri);
return 1;
}
 
http/BUILD added: 35, removed: 35, total 0
@@ -1,7 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
 
cc_library(
name = "http",
name = "protocol",
srcs = ["get.cpp"],
hdrs = ["get.h"],
visibility = ["//visibility:public"],
 
http/get.cpp added: 35, removed: 35, total 0
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: BSD-2-Clause
 
#include "http/get.h"
#include "protocol/get.h"
 
#include <asio.hpp>
#include <asio/ssl.hpp>
@@ -19,7 +19,7 @@
 
using namespace std::string_view_literals;
 
namespace http {
namespace protocol {
namespace {
 
std::pair<std::string_view, std::string_view> split(std::string_view str, std::string_view sep) {
@@ -163,4 +163,4 @@ std::string to_string(std::map<std::string, std::string> const &headers) {
return ss.str();
}
 
} // namespace http
} // namespace protocol
 
http/get.h added: 35, removed: 35, total 0
@@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: BSD-2-Clause
 
#ifndef HTTP_GET_H_
#define HTTP_GET_H_
#ifndef PROTOCOL_GET_H_
#define PROTOCOL_GET_H_
 
#include "uri/uri.h"
 
@@ -11,7 +11,7 @@
#include <string>
#include <string_view>
 
namespace http {
namespace protocol {
 
enum class Error {
Ok,
@@ -37,6 +37,6 @@ Response get(uri::Uri const &uri);
 
std::string to_string(std::map<std::string, std::string> const &headers);
 
} // namespace http
} // namespace protocol
 
#endif