pica/request/request.h

64 lines
1.3 KiB
C++

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <memory>
#include <stdexcept>
#include <string_view>
#include <array>
#include <map>
#include <fcgiapp.h>
#include <nlohmann/json.hpp>
#include "stream/ostream.h"
class Response;
class Request {
public:
enum class State {
initial,
accepted,
responding,
responded
};
enum class Method {
get,
post,
unknown
};
Request();
~Request();
Request(const Request& other) = delete;
Request(Request&& other) = delete;
Request& operator = (const Request& other) = delete;
Request& operator = (Request&& other) = delete;
bool wait(int socketDescriptor);
void terminate();
Method method() const;
State currentState() const;
OStream getOutputStream(const Response* response);
OStream getErrorStream(const Response* response);
void responseIsComplete(const Response* response);
std::string getPath(const std::string& serverName) const;
std::string getServerName() const;
void printEnvironment(std::ostream& out);
void printEnvironment(nlohmann::json& out);
private:
void validateResponse(const Response* response);
private:
State state;
FCGX_Request raw;
const Response* response;
};