Deutsch

Воспоминания Си Джи Ай 15.02.2025

3 дня назад, 08:35
Re: Воспоминания Си Джи Ай 15.02.2025
 
uscheswoi_82 патриот
в ответ uscheswoi_82 3 дня назад, 08:26

Я сегодня написал простенький CGI фреймворк на Си++. Вот код

Request.hpp:

#ifndef _REQUEST
#define _REQUEST
#include <iostream>
#include <string>
using namespace std;
class Request {
private:
  string strContentType;

public:
  ~Request();
  void setContentType(string strContentType);
  string get_method();
  string get_query();
  string get_uri();
  string get_cookies();
};
#endif


Request.cpp:

#include "request.hpp"

void Request::setContentType(string strContentType) {
  this->strContentType = strContentType;
  cout << "Content-Type:" << strContentType << "\n\r" << endl;
}

string Request::get_method() {
  return getenv("REQUEST_METHOD");
}

string Request::get_query() {
  return getenv("QUERY_STRING");
}

string Request::get_uri() {
  return getenv("REQUEST_URI");
}

string Request::get_cookies() {
  return getenv("HTTP_COOKIE");
}


Response.hpp:

#ifndef _RESPONSE
#define _RESPONSE
#include <iostream>
#include <string>

using namespace std;
class Response {
public:
  Response();
  void render(string strData);
};
#endif


Response.cpp:

#include "response.hpp"
Response::Response() {}

void Response::render(string strData) {
  cout << strData << endl;
}


Main.cpp:

#include <iostream>
#include "request.hpp"
#include "response.hpp"


int main(int argc, char** argv) {
  Request *req = new Request();
  Response *resp = new Response();
  req->setContentType("text/html");
  resp->render("<!DOCTYPE HTML><html><head>
               <title>CGIDemo 2025</title> 
               </head><body><h1 style=\"
               color:red;\">Hello World!</h1>
               </body></html>\n");
  return 0;
}



Вуаля а вот и результат!



Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнение
 

Перейти на