#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/server/http_server.h"
#include <string_view>
#include <utility>
#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/sys_byteorder.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "net/base/net_errors.h"
#include "net/server/http_connection.h"
#include "net/server/http_server_request_info.h"
#include "net/server/http_server_response_info.h"
#include "net/server/web_socket.h"
#include "net/server/web_socket_parse_result.h"
#include "net/socket/server_socket.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"
namespace net {
namespace {
constexpr NetworkTrafficAnnotationTag
kHttpServerErrorResponseTrafficAnnotation = …;
}
HttpServer::HttpServer(std::unique_ptr<ServerSocket> server_socket,
HttpServer::Delegate* delegate)
: … { … }
HttpServer::~HttpServer() = default;
void HttpServer::AcceptWebSocket(
int connection_id,
const HttpServerRequestInfo& request,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::SendOverWebSocket(
int connection_id,
std::string_view data,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::SendRaw(int connection_id,
const std::string& data,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::SendResponse(int connection_id,
const HttpServerResponseInfo& response,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::Send(int connection_id,
HttpStatusCode status_code,
const std::string& data,
const std::string& content_type,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::Send200(int connection_id,
const std::string& data,
const std::string& content_type,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::Send404(int connection_id,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::Send500(int connection_id,
const std::string& message,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::Close(int connection_id) { … }
int HttpServer::GetLocalAddress(IPEndPoint* address) { … }
void HttpServer::SetReceiveBufferSize(int connection_id, int32_t size) { … }
void HttpServer::SetSendBufferSize(int connection_id, int32_t size) { … }
void HttpServer::DoAcceptLoop() { … }
void HttpServer::OnAcceptCompleted(int rv) { … }
int HttpServer::HandleAcceptResult(int rv) { … }
void HttpServer::DoReadLoop(HttpConnection* connection) { … }
void HttpServer::OnReadCompleted(int connection_id, int rv) { … }
int HttpServer::HandleReadResult(HttpConnection* connection, int rv) { … }
void HttpServer::DoWriteLoop(HttpConnection* connection,
NetworkTrafficAnnotationTag traffic_annotation) { … }
void HttpServer::OnWriteCompleted(
int connection_id,
NetworkTrafficAnnotationTag traffic_annotation,
int rv) { … }
int HttpServer::HandleWriteResult(HttpConnection* connection, int rv) { … }
namespace {
enum header_parse_inputs { … };
enum header_parse_states { … };
const int parser_state[MAX_STATES][MAX_INPUTS] = …;
int charToInput(char ch) { … }
}
bool HttpServer::ParseHeaders(const char* data,
size_t data_len,
HttpServerRequestInfo* info,
size_t* ppos) { … }
HttpConnection* HttpServer::FindConnection(int connection_id) { … }
bool HttpServer::HasClosedConnection(HttpConnection* connection) { … }
void HttpServer::DestroyClosedConnections() { … }
}