//发送头部 bool CHttpProtocol::SendHeader(PREQUEST pReq) { int iResult; char Header[2048]; while(false == FileExist(pReq)) {//文件不存在,更改到错误标志文件路径 strcpy_s(pReq->szFileName, strRootDir); strcat_s(pReq->szFileName, "/error.html"); } GetCurTime(Time); //取得文件长度 DWORD length; length = GetFileSize(pReq->hFile, NULL); //取得文件的last-modified时间 char last_modified[100]; GetLastModified(pReq->hFile, (char*)last_modified); //取得文件的类型 char ContenType[100]; GetContenType(pReq, (char*)ContenType); sprintf_s(Header, sizeof(Header), "HTTP/1.0 %s\r\nDate: %s\r\nServer: %s\r\nContent-Type: %s\r\nContent-Length: %d\r\nLast-Modified: %s\r\n\r\n", HTTP_STATUS_OK, Time, // Date "My Web Server", // Server ContenType, // Content-Type length, // Content-length last_modified); // Last-Modified //发送头部 iResult = send(pReq->Socket, Header, strlen(Header), 0); pReq->dwSend += iResult; if (iResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); return false; } return true; }
Date File::GetLastModifiedDate(ErrorResult& aRv) { int64_t value = GetLastModified(aRv); if (aRv.Failed()) { return Date(); } return Date(JS::TimeClip(value)); }