@@ -46,11 +46,11 @@ void Http::OnRequestRecv(std::string msg) {
4646 if (parseRet || !validPath)
4747 processError (" 400" , " Bad Request" , true );
4848 else if (isHttpVersionValid (_request.getVersion ()) == false ) {
49- processError (" 505" , " HTTP Version Not Supported" );
50- _response.setHeader (" Upgrade" , " HTTP /" HTTP_VERSION);
49+ processError (" 505" , " HTTP Version Not Supported" , true );
50+ _response.setHeader (" Upgrade" , PROTOCOL " /" HTTP_VERSION);
5151 _response.setHeader (" Connection" , " Upgrade" );
5252 } else if (isMehodImplemented (_request.getMethod ()) == false )
53- processError (" 501" , " Not Implemented" );
53+ processError (" 501" , " Not Implemented" , true );
5454 if (_response.isReady ()) return sendResponse ();
5555 setReadState (HEAD);
5656}
@@ -129,7 +129,7 @@ void Http::OnBodyRecv(std::string msg) {
129129
130130void Http::OnCgiRecv (std::string msg) {
131131 accessLog_g.write (" CGI out: \" " + msg + " \" " , VERBOSE);
132- _response.init (" HTTP/1.1 " , " 200" , " OK" );
132+ _response.init (PROTOCOL " / " HTTP_VERSION , " 200" , " OK" );
133133 int bodySize = msg.size ();
134134 _response.setBody (new std::istringstream (msg));
135135
@@ -233,7 +233,7 @@ void Http::processFile(std::string uri) {
233233 }
234234
235235 // Load the file
236- _response.init (" HTTP/1.1 " , " 200" , " OK" );
236+ _response.init (PROTOCOL " / " HTTP_VERSION , " 200" , " OK" );
237237 _response.setBody (new std::ifstream (file.getPath ().c_str ()));
238238 int bodySize = file.size ();
239239 if (_response.getBody ()->good () == false || bodySize < 0 )
@@ -256,7 +256,7 @@ void Http::processCgi(std::string contentLength) {
256256 // const values:
257257 env.push_back (" GATEWAY_INTERFACE=CGI/1.1" );
258258 env.push_back (" SERVER_SOFTWARE=" WEBSERV_ID);
259- env.push_back (" SERVER_PROTOCOL=HTTP /" HTTP_VERSION);
259+ env.push_back (" SERVER_PROTOCOL=" PROTOCOL " /" HTTP_VERSION);
260260
261261 // request specific values:
262262
@@ -378,15 +378,15 @@ void Http::processPostData(const std::string &data) {
378378
379379void Http::getPutResponse (std::string uri) {
380380 if (_newFile)
381- _response.init (" HTTP/1.1 " , " 201" , " Created" );
381+ _response.init (PROTOCOL " / " HTTP_VERSION , " 201" , " Created" );
382382 else
383- _response.init (" HTTP/1.1 " , " 204" , " No Content" );
383+ _response.init (PROTOCOL " / " HTTP_VERSION , " 204" , " No Content" );
384384 _response.setHeader (" Location" , getAbsoluteUri (uri));
385385 _response.setReady ();
386386}
387387
388388void Http::processOptions (std::string uri) {
389- _response.init (" HTTP/1.1 " , " 200" , " OK" );
389+ _response.init (PROTOCOL " / " HTTP_VERSION , " 200" , " OK" );
390390 _response.setHeader (" Allow" ,
391391 concatenate (getAllowedMethods (uri != " *" ), " , " ));
392392 _response.setReady ();
@@ -401,12 +401,12 @@ void Http::processDelete(std::string uri) {
401401 if (!file.readable ()) return processError (" 403" , " Forbidden" );
402402 if (std::remove (file.getPath ().c_str ()) != 0 )
403403 return processError (" 500" , " Internal Server Error" );
404- _response.init (" HTTP/1.1 " , " 204" , " No Content" );
404+ _response.init (PROTOCOL " / " HTTP_VERSION , " 204" , " No Content" );
405405 _response.setReady ();
406406}
407407
408408void Http::processAutoindex (std::string uri) {
409- _response.init (" HTTP/1.1 " , " 200" , " OK" );
409+ _response.init (PROTOCOL " / " HTTP_VERSION , " 200" , " OK" );
410410 _response.setBody (new std::stringstream (" <html>\r\n <head><title>Index of " +
411411 uri + " </title></head>\r\n <body>" ));
412412 std::stringstream *body = (std::stringstream *)_response.getBody ();
@@ -450,13 +450,13 @@ void Http::processAutoindex(std::string uri) {
450450}
451451
452452void Http::processRedirect (std::string uri) {
453- _response.init (" HTTP/1.1 " , " 301" , " Moved Permanently" );
453+ _response.init (PROTOCOL " / " HTTP_VERSION , " 301" , " Moved Permanently" );
454454 _response.setHeader (" Location" , getAbsoluteUri (uri));
455455 _response.setReady ();
456456}
457457
458458void Http::processError (std::string code, std::string reason, bool close) {
459- _response.init (" HTTP/1.1 " , code, reason);
459+ _response.init (PROTOCOL " / " HTTP_VERSION , code, reason);
460460
461461 if (_virtualHost && _virtualHost->getContext ().exists (" error_page" )) {
462462 std::vector<std::vector<std::string> > &pages =
@@ -595,13 +595,13 @@ bool Http::isMehodImplemented(std::string method) const {
595595}
596596
597597bool Http::isHttpVersionValid (std::string version) const {
598- if (startsWith (version, " HTTP /" ))
599- version.erase (0 , std::string (" HTTP /" ).size ());
598+ if (startsWith (version, PROTOCOL " /" ))
599+ version.erase (0 , std::string (PROTOCOL " /" ).size ());
600600 std::vector<std::string> in = split<std::vector<std::string> >(version, " ." );
601601 if (in.size () < 1 || in.size () > 2 ) return false ;
602602
603603 std::vector<std::string> reqired =
604- split<std::vector<std::string> >(HTTP_VERSION, " ." );
604+ split<std::vector<std::string> >(HTTP_VERSION, " ." , true );
605605 if (reqired.size () < 1 || reqired.size () > 2 || in.size () != reqired.size ())
606606 return false ;
607607
0 commit comments