|
1 | 1 | /** |
2 | 2 | httpserver |
3 | 3 | HTTPServer.cpp |
4 | | - Copyright 2011-2012 Ramsey Kant |
| 4 | + Copyright 2011-2014 Ramsey Kant |
5 | 5 |
|
6 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | you may not use this file except in compliance with the License. |
@@ -394,11 +394,11 @@ void HTTPServer::handleRequest(Client *cl, HTTPRequest* req) { |
394 | 394 | } |
395 | 395 |
|
396 | 396 | std::cout << "[" << cl->getClientIP() << "] " << req->methodIntToStr(req->getMethod()) << " " << req->getRequestUri() << std::endl; |
397 | | - /*cout << "Headers:" << endl; |
| 397 | + /*std::cout << "Headers:" << std::endl; |
398 | 398 | for(int i = 0; i < req->getNumHeaders(); i++) { |
399 | | - cout << req->getHeaderStr(i) << endl; |
| 399 | + std::cout << req->getHeaderStr(i) << std::endl; |
400 | 400 | } |
401 | | - cout << endl;*/ |
| 401 | + std::cout << std::endl;*/ |
402 | 402 |
|
403 | 403 | // Retrieve the host specified in the request (Required for HTTP/1.1 compliance) |
404 | 404 | std::string host = req->getHeaderValue("Host"); |
@@ -453,9 +453,13 @@ void HTTPServer::handleGet(Client* cl, HTTPRequest* req, ResourceHost* resHost) |
453 | 453 | // Only send a message body if it's a GET request. Never send a body for HEAD |
454 | 454 | if(req->getMethod() == Method(GET)) |
455 | 455 | resp->setData(r->getData(), r->getSize()); |
456 | | - |
457 | | - // Check if the client prefers to close the connection |
458 | | - bool dc = req->getHeaderValue("Connection").compare("close") == 0; |
| 456 | + |
| 457 | + bool dc = false; |
| 458 | + |
| 459 | + // If Connection: close is specified, the connection should be terminated after the request is serviced |
| 460 | + std::string connection_val = req->getHeaderValue("Connection"); |
| 461 | + if(connection_val.compare("close") == 0) |
| 462 | + dc = true; |
459 | 463 |
|
460 | 464 | sendResponse(cl, resp, dc); |
461 | 465 | delete resp; |
|
0 commit comments