From 96a4468913d14d1830ef1ce1b3896ecd3c216854 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 28 Apr 2019 18:22:49 +0000 Subject: [PATCH] Convenience constructor for FastCGIHeader --- fastcgi_parse.h | 8 +++++++- fastcgi_request.cpp | 16 +++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/fastcgi_parse.h b/fastcgi_parse.h index 7f1cf8d..d2d58de 100644 --- a/fastcgi_parse.h +++ b/fastcgi_parse.h @@ -3,7 +3,13 @@ #include struct FastCGIHeader { - uint8_t version; + FastCGIHeader(uint8_t type_in, uint16_t request_id, uint16_t content_length) + : type(type_in) { + SetRequestId(request_id); + SetContentLength(content_length); + } + + uint8_t version = 1; uint8_t type; private: uint16_t request_id_; // network byte order diff --git a/fastcgi_request.cpp b/fastcgi_request.cpp index 231600e..aefbbcc 100644 --- a/fastcgi_request.cpp +++ b/fastcgi_request.cpp @@ -40,21 +40,11 @@ void FastCGIRequest::WriteBody(const std::string_view& body) { } void FastCGIRequest::End() { - FastCGIHeader output_header; - FastCGIHeader end_header; - FastCGIEndRequest end; - const auto output_len = out_buf_.ReadMaxLen(); - output_header.version = 1; - output_header.type = 6; - output_header.SetRequestId(request_id_); - output_header.SetContentLength(output_len); - - end_header.version = 1; - end_header.type = 3; - end_header.SetRequestId(request_id_); - end_header.SetContentLength(sizeof(end)); + FastCGIHeader output_header(6, request_id_, output_len); + FastCGIEndRequest end; + FastCGIHeader end_header(3, request_id_, sizeof(end)); std::vector vecs{ iovec{