Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Created non-templated base classes #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Created non-templated base classes #211

wants to merge 1 commit into from

Conversation

eidheim
Copy link
Owner

@eidheim eidheim commented Feb 17, 2018

The base class is no longer a template class, making HTTP/HTTPS independent polymorphism on the client/server classes possible.

At first I didn't much like the idea due to added complexity, but now I'm pretty comfortable with the changes since the final solution is somewhat clean if not cleaner than before. Feedback is required though.

Related to issue #168. See also discussion on PR #208.

Example use:

#include "client_https.hpp"
#include "server_https.hpp"
#include <vector>

int main() {
  auto io_service = std::make_shared<SimpleWeb::asio::io_service>();
  std::vector<std::unique_ptr<SimpleWeb::ServerBase>> servers;

  servers.emplace_back(new SimpleWeb::Server<SimpleWeb::HTTP>());
  servers.back()->io_service = io_service;
  servers.back()->config.port = 8080;
  servers.back()->default_resource["GET"] = [](std::shared_ptr<SimpleWeb::Server<>::Response> response,
                                               std::shared_ptr<SimpleWeb::Server<>::Request> /*request*/) {
    response->write("Hello World");
  };

  servers.emplace_back(new SimpleWeb::Server<SimpleWeb::HTTPS>("server.crt", "server.key"));
  servers.back()->io_service = io_service;
  servers.back()->config.port = 8081;
  servers.back()->default_resource["GET"] = servers[0]->default_resource["GET"];

  for(auto &server : servers)
    server->start();

  io_service->run();
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant