diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-03-29 20:27:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-03-29 20:27:48 +0100 |
| commit | 79c2769714d1b41416360cbb23a64f5cf68abc1f (patch) | |
| tree | 2641bd617447c323839e26df10a4d1e919d77bc7 /lib | |
| parent | 02856414d220a5a4cb8d196de490698dd0cc0c70 (diff) | |
module: add: CGI header.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/cgi.cc | 8 | ||||
| -rw-r--r-- | lib/stdx/cgi.hpp | 62 | ||||
| -rw-r--r-- | lib/stdx/opt.hpp | 8 |
3 files changed, 74 insertions, 4 deletions
diff --git a/lib/cgi.cc b/lib/cgi.cc new file mode 100644 index 0000000..d92a455 --- /dev/null +++ b/lib/cgi.cc @@ -0,0 +1,8 @@ +/* + * File: cgi.cc + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss all rights reserved. + */ + +#include <stdx/cgi.hpp> + diff --git a/lib/stdx/cgi.hpp b/lib/stdx/cgi.hpp new file mode 100644 index 0000000..317ee6c --- /dev/null +++ b/lib/stdx/cgi.hpp @@ -0,0 +1,62 @@ +/* + * File: cgi.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss all rights reserved. + */ + +#ifndef _STDX_CGI_HPP +#define _STDX_CGI_HPP + +#include <cstdio> +#include <string> +#include <sstream> + +namespace stdx +{ + namespace web + { + class cgi_writer final + { + cgi_writer& eval_(const std::string& mime, const std::stringstream& ss) noexcept + { + std::printf("Content-Type: %s\r\n", mime.c_str()); + std::printf("Server: %s\r\n", "STDX CGI"); + std::printf("Content-Length: %ld\r\n\r\n", ss.str().size()); + std::printf("%s", ss.str().c_str()); + + return *this; + } + + public: + explicit cgi_writer() + { + } + + cgi_writer& operator=(const cgi_writer&) = default; + cgi_writer(const cgi_writer&) = default; + + public: + cgi_writer& eval_html(const std::stringstream& ss_html) + { + return this->eval_("text/html", ss_html); + } + + cgi_writer& eval_xml(const std::stringstream& ss_html) + { + return this->eval_("application/xml", ss_html); + } + + cgi_writer& eval_json(const std::stringstream& ss_html) + { + return this->eval_("application/json", ss_html); + } + + cgi_writer& eval_js(const std::stringstream& ss_html) + { + return this->eval_("text/javascript", ss_html); + } + }; + } // namespace details +} // namespace stdx + +#endif // ifndef _STDX_CGI_HPP
\ No newline at end of file diff --git a/lib/stdx/opt.hpp b/lib/stdx/opt.hpp index 66ef4a5..5624c0a 100644 --- a/lib/stdx/opt.hpp +++ b/lib/stdx/opt.hpp @@ -1,11 +1,11 @@ /* - * File: stdx.hpp + * File: opt.hpp * Author: Amlal El Mahrouss, * Copyright 2023-2025, Amlal El Mahrouss all rights reserved. */ -#ifndef _STDX_HPP -#define _STDX_HPP +#ifndef _STDX_OPT_HPP +#define _STDX_OPT_HPP #include <stdexcept> #include <utility> @@ -107,4 +107,4 @@ namespace stdx } /* namespace stdx */ -#endif /* ifndef _STDX_HPP */ +#endif /* ifndef _STDX_OPT_HPP */ |
