2020-08-20 00:27:27 +02:00
|
|
|
// Copyright (c) 2020 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "tests/ceftests/test_server.h"
|
|
|
|
|
2022-07-31 01:53:48 +02:00
|
|
|
#include <vector>
|
2020-08-20 00:27:27 +02:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "tests/ceftests/test_server_manager.h"
|
|
|
|
|
2020-08-20 00:27:27 +02:00
|
|
|
namespace test_server {
|
|
|
|
|
|
|
|
// Must use a different port than server_unittest.cc.
|
2022-07-31 03:17:40 +02:00
|
|
|
const char kHttpServerAddress[] = "127.0.0.1";
|
2023-06-01 16:06:15 +02:00
|
|
|
const uint16_t kHttpServerPort = 8098;
|
2022-07-31 03:17:40 +02:00
|
|
|
|
2022-07-29 22:05:20 +02:00
|
|
|
const char kIncompleteDoNotSendData[] = "DO NOT SEND";
|
2020-08-20 00:27:27 +02:00
|
|
|
|
2022-07-31 01:53:48 +02:00
|
|
|
CefRefPtr<CefResponse> Create404Response() {
|
|
|
|
auto response = CefResponse::Create();
|
|
|
|
response->SetStatus(404);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stop(base::OnceClosure callback) {
|
|
|
|
// Stop both HTTPS and HTTP servers in a chain.
|
|
|
|
Manager::Stop(base::BindOnce(
|
|
|
|
[](base::OnceClosure callback) {
|
|
|
|
Manager::Stop(std::move(callback),
|
|
|
|
/*https_server=*/false);
|
|
|
|
},
|
|
|
|
std::move(callback)),
|
|
|
|
/*https_server=*/true);
|
2020-08-20 00:27:27 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 03:17:40 +02:00
|
|
|
std::string GetOrigin(bool https_server) {
|
|
|
|
return Manager::GetOrigin(https_server);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetScheme(bool https_server) {
|
|
|
|
return https_server ? "https" : "http";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetHost(bool https_server, bool include_port) {
|
|
|
|
const auto& origin = GetOrigin(https_server);
|
|
|
|
|
|
|
|
const auto scheme_offset = origin.find("//");
|
|
|
|
const auto& origin_without_scheme = origin.substr(scheme_offset + 2);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (include_port) {
|
2022-07-31 03:17:40 +02:00
|
|
|
return origin_without_scheme;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-07-31 03:17:40 +02:00
|
|
|
|
|
|
|
const auto port_offset = origin_without_scheme.find(':');
|
|
|
|
return origin_without_scheme.substr(0, port_offset);
|
|
|
|
}
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
} // namespace test_server
|