19
19
// enum for http responses
20
20
std::map<int , std::string> *WSJCppLightWebHttpResponse::g_mapReponseDescription = nullptr ;
21
21
22
- // deprecated
23
- std::string WSJCppLightWebHttpResponse::RESP_OK = " HTTP/1.1 200 OK" ;
24
- std::string WSJCppLightWebHttpResponse::RESP_BAD_REQUEST = " HTTP/1.1 400 Bad Request" ;
25
- std::string WSJCppLightWebHttpResponse::RESP_FORBIDDEN = " HTTP/1.1 403 Forbidden" ;
26
- std::string WSJCppLightWebHttpResponse::RESP_NOT_FOUND = " HTTP/1.1 404 Not Found" ;
27
- std::string WSJCppLightWebHttpResponse::RESP_PAYLOAD_TOO_LARGE = " HTTP/1.1 413 Payload Too Large" ;
28
- std::string WSJCppLightWebHttpResponse::RESP_INTERNAL_SERVER_ERROR = " HTTP/1.1 500 Internal Server Error" ;
29
- std::string WSJCppLightWebHttpResponse::RESP_NOT_IMPLEMENTED = " HTTP/1.1 501 Not Implemented" ;
30
-
31
22
// ----------------------------------------------------------------------
32
23
33
24
WSJCppLightWebHttpResponse::WSJCppLightWebHttpResponse (int nSockFd) {
@@ -41,6 +32,7 @@ WSJCppLightWebHttpResponse::WSJCppLightWebHttpResponse(int nSockFd) {
41
32
WSJCppLightWebHttpResponse::g_mapReponseDescription->insert (std::pair<int , std::string>(413 , " HTTP/1.1 413 Payload Too Large" ));
42
33
WSJCppLightWebHttpResponse::g_mapReponseDescription->insert (std::pair<int , std::string>(500 , " HTTP/1.1 500 Internal Server Error" ));
43
34
WSJCppLightWebHttpResponse::g_mapReponseDescription->insert (std::pair<int , std::string>(501 , " HTTP/1.1 501 Not Implemented" ));
35
+ WSJCppLightWebHttpResponse::g_mapReponseDescription->insert (std::pair<int , std::string>(408 , " HTTP/1.1 408 Request Time-out" ));
44
36
}
45
37
46
38
m_nSockFd = nSockFd;
@@ -103,6 +95,13 @@ WSJCppLightWebHttpResponse &WSJCppLightWebHttpResponse::notImplemented() {
103
95
104
96
// ----------------------------------------------------------------------
105
97
98
+ WSJCppLightWebHttpResponse &WSJCppLightWebHttpResponse::requestTimeout () {
99
+ m_nResponseCode = 408 ;
100
+ return *this ;
101
+ }
102
+
103
+ // ----------------------------------------------------------------------
104
+
106
105
WSJCppLightWebHttpResponse &WSJCppLightWebHttpResponse::noCache () {
107
106
m_sCacheControl = " no-cache, no-store, must-revalidate" ;
108
107
return *this ;
@@ -209,33 +208,6 @@ void WSJCppLightWebHttpResponse::sendOptions(const std::string &sOptions) {
209
208
210
209
// ----------------------------------------------------------------------
211
210
212
- void WSJCppLightWebHttpResponse::sendRequestTimeOut () {
213
- std::string sResponse = " I don't understand you! Are you just a machine? Or maybe hacker?" ;
214
- /*
215
- HTTP/1.0 408 Request Time-out
216
- Cache-Control: no-cache
217
- Connection: close
218
- Content-Type: text/html
219
-
220
- <html><body><h1>408 Request Time-out</h1>
221
- Your browser didn't send a complete request in time.
222
- </body></html>
223
- */
224
-
225
- if (m_bClosed) {
226
- WSJCppLog::warn (TAG, " Already sended response" );
227
- return ;
228
- }
229
- m_bClosed = true ;
230
-
231
- WSJCppLog::info (TAG, " \n Response: \n >>>\n " + sResponse + " \n <<<" );
232
-
233
- send (m_nSockFd, sResponse .c_str (), sResponse .length (),0 );
234
- close (m_nSockFd);
235
- }
236
-
237
- // ----------------------------------------------------------------------
238
-
239
211
void WSJCppLightWebHttpResponse::sendFile (const std::string &sFilePath ) {
240
212
241
213
// read data from file
@@ -279,21 +251,7 @@ void WSJCppLightWebHttpResponse::sendBuffer(const std::string &sFilePath, const
279
251
return ;
280
252
}
281
253
m_bClosed = true ;
282
-
283
- // #if __APPLE__
284
- // send(m_nSockFd, sResponse.c_str(), sResponse.length(), SO_NOSIGPIPE);
285
- // send(m_nSockFd, pData, nSize, SO_NOSIGPIPE);
286
- // // #if
287
- // // TARGET_OS_MAC
288
-
289
- // #else
290
- // SO_NOSIGPIPE
291
254
write (m_nSockFd, sResponse .c_str (), sResponse .length ());
292
255
write (m_nSockFd, pBuffer, nBufferSize);
293
-
294
- // send(m_nSockFd, sResponse.c_str(), sResponse.length(), MSG_CONFIRM);
295
- // send(m_nSockFd, pBuffer, nBufferSize, MSG_CONFIRM);
296
- // #endif
297
-
298
256
close (m_nSockFd);
299
257
}
0 commit comments