From 8e51dd38df59ffae44eaa0d12712bf0d05c7880e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 3 Mar 2018 01:51:05 +0000 Subject: Standard header formatter Use CTFs in common library for formatting header output. --- icespider/common/formatters.h | 12 ++++++++++++ icespider/fcgi/cgiRequestBase.cpp | 8 +++----- icespider/testing/testRequest.cpp | 7 +++---- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 icespider/common/formatters.h diff --git a/icespider/common/formatters.h b/icespider/common/formatters.h new file mode 100644 index 0000000..1ec6a6b --- /dev/null +++ b/icespider/common/formatters.h @@ -0,0 +1,12 @@ +#ifndef ICESPIDER_COMMON_FORMATTERS_H +#define ICESPIDER_COMMON_FORMATTERS_H + +#include + +namespace IceSpider { + AdHocFormatter(StatusFmt, "Status: %? %?\r\n\r\n"); + AdHocFormatter(HdrFmt, "%?: %?\r\n"); +} + +#endif + diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp index 3b03440..74f1d1f 100644 --- a/icespider/fcgi/cgiRequestBase.cpp +++ b/icespider/fcgi/cgiRequestBase.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include namespace ba = boost::algorithm; @@ -190,15 +190,13 @@ namespace IceSpider { void CgiRequestBase::response(short statusCode, const std::string & statusMsg) const { - getOutputStream() - << "Status: " << statusCode << " " << statusMsg << "\r\n" - << "\r\n"; + StatusFmt::write(getOutputStream(), statusCode, statusMsg); } void CgiRequestBase::setHeader(const std::string & header, const std::string & value) const { - getOutputStream() << header << ": " << value << "\r\n"; + HdrFmt::write(getOutputStream(), header, value); } bool diff --git a/icespider/testing/testRequest.cpp b/icespider/testing/testRequest.cpp index e101dfd..c7fe4d3 100644 --- a/icespider/testing/testRequest.cpp +++ b/icespider/testing/testRequest.cpp @@ -1,6 +1,7 @@ #include "testRequest.h" #include #include +#include namespace IceSpider { TestRequest::TestRequest(const Core * c, HttpMethod m, const std::string & p) : @@ -114,15 +115,13 @@ namespace IceSpider { void TestRequest::response(short statusCode, const std::string & statusMsg) const { - getOutputStream() - << "Status: " << statusCode << " " << statusMsg << "\r\n" - << "\r\n"; + StatusFmt::write(getOutputStream(), statusCode, statusMsg); } void TestRequest::setHeader(const std::string & header, const std::string & value) const { - getOutputStream() << header << ": " << value << "\r\n"; + HdrFmt::write(getOutputStream(), header, value); } std::ostream & -- cgit v1.2.3