2023-12-10 23:23:15 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-11-21 22:19:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string_view>
|
2023-12-14 22:17:28 +00:00
|
|
|
#include <string>
|
2023-12-13 20:33:11 +00:00
|
|
|
#include <array>
|
|
|
|
#include <map>
|
2023-11-21 22:19:08 +00:00
|
|
|
|
|
|
|
#include <fcgiapp.h>
|
|
|
|
|
2023-11-23 19:57:32 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2023-11-21 22:19:08 +00:00
|
|
|
#include "stream/ostream.h"
|
2023-12-14 22:17:28 +00:00
|
|
|
#include "utils/formdecode.h"
|
2023-11-21 22:19:08 +00:00
|
|
|
|
2023-12-13 20:33:11 +00:00
|
|
|
class Response;
|
2023-11-21 22:19:08 +00:00
|
|
|
class Request {
|
|
|
|
public:
|
|
|
|
enum class State {
|
|
|
|
initial,
|
|
|
|
accepted,
|
2023-12-13 20:33:11 +00:00
|
|
|
responding,
|
2023-11-21 22:19:08 +00:00
|
|
|
responded
|
|
|
|
};
|
|
|
|
|
2023-12-13 20:33:11 +00:00
|
|
|
enum class Method {
|
|
|
|
get,
|
|
|
|
post,
|
|
|
|
unknown
|
|
|
|
};
|
|
|
|
|
2023-11-21 22:19:08 +00:00
|
|
|
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();
|
|
|
|
|
2023-12-13 20:33:11 +00:00
|
|
|
Method method() const;
|
|
|
|
State currentState() const;
|
2023-12-14 22:17:28 +00:00
|
|
|
bool isFormUrlEncoded() const;
|
|
|
|
unsigned int contentLength() const;
|
|
|
|
std::map<std::string, std::string> getForm() const;
|
2023-12-13 20:33:11 +00:00
|
|
|
|
|
|
|
OStream getOutputStream(const Response* response);
|
|
|
|
OStream getErrorStream(const Response* response);
|
|
|
|
void responseIsComplete(const Response* response);
|
2023-11-21 22:19:08 +00:00
|
|
|
|
2023-11-23 19:57:32 +00:00
|
|
|
std::string getPath(const std::string& serverName) const;
|
2023-11-21 22:19:08 +00:00
|
|
|
std::string getServerName() const;
|
|
|
|
void printEnvironment(std::ostream& out);
|
2023-11-23 19:57:32 +00:00
|
|
|
void printEnvironment(nlohmann::json& out);
|
2023-11-21 22:19:08 +00:00
|
|
|
|
2023-12-13 20:33:11 +00:00
|
|
|
private:
|
|
|
|
void validateResponse(const Response* response);
|
|
|
|
|
2023-11-21 22:19:08 +00:00
|
|
|
private:
|
|
|
|
State state;
|
|
|
|
FCGX_Request raw;
|
2023-12-13 20:33:11 +00:00
|
|
|
const Response* response;
|
2023-11-21 22:19:08 +00:00
|
|
|
};
|