void HttpServlet::DoPut(HttpServletRequest& request, HttpServletResponse& response) { std::string protocol = request.GetProtocol(); std::string msg = "Http PUT method not supported"; if (protocol.size() > 2 && protocol.substr(protocol.size()-3) == "1.1") { response.SendError(HttpServletResponse::SC_METHOD_NOT_ALLOWED, msg); } else { response.SendError(HttpServletResponse::SC_BAD_REQUEST, msg); } }
void HttpServlet::Service(HttpServletRequest& request, HttpServletResponse& response) { std::string method = request.GetMethod(); if (method == METHOD_GET) { long long lastModified = GetLastModified(request); if (lastModified == -1) { // servlet doesn't support if-modified-since, no reason // to go through further expensive logic DoGet(request, response); } else { long long ifModifiedSince = request.GetDateHeader(HEADER_IFMODSINCE); std::cout << "ifModifiedSince: " << ifModifiedSince << std::endl; std::cout << "lastModified: " << lastModified << std::endl; if (ifModifiedSince < lastModified) { // If the servlet mod time is later, call doGet() // Round down to the nearest second for a proper compare // A ifModifiedSince of -1 will always be less MaybeSetLastModified(response, lastModified); DoGet(request, response); } else { response.SetStatus(HttpServletResponse::SC_NOT_MODIFIED); } } } else if (method == METHOD_HEAD) { long long lastModified = GetLastModified(request); MaybeSetLastModified(response, lastModified); DoHead(request, response); } else if (method == METHOD_POST) { DoPost(request, response); } else if (method == METHOD_PUT) { DoPut(request, response); } else if (method == METHOD_DELETE) { DoDelete(request, response); } // else if (method == METHOD_OPTIONS) // { // DoOptions(request, response); // } else if (method == METHOD_TRACE) { DoTrace(request,response); } else { // // Note that this means NO servlet supports whatever // method was requested, anywhere on this server. // std::string errMsg = std::string("Http method ") + method + " not implemented"; response.SendError(HttpServletResponse::SC_NOT_IMPLEMENTED, errMsg); } }