Skip to content

Commit 04df700

Browse files
committed
Added function to application for cleaning outgoing headers
1 parent 5519c28 commit 04df700

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

httpserverapp.userprefs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Properties>
2-
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
33
<MonoDevelop.Ide.Workbench ActiveDocument="httpserverapp/Utils.cpp">
44
<Files>
55
<File FileName="httpserverapp/Main.h" Line="1" Column="1" />
6-
<File FileName="httpserverapp/Main.cpp" Line="1" Column="1" />
6+
<File FileName="httpserverapp/Main.cpp" Line="58" Column="2" />
77
<File FileName="httpserverapp/ServerRequest.h" Line="1" Column="1" />
8-
<File FileName="httpserverapp/ServerResponse.h" Line="1" Column="1" />
9-
<File FileName="httpserverapp/Utils.h" Line="1" Column="1" />
8+
<File FileName="httpserverapp/ServerResponse.h" Line="7" Column="1" />
9+
<File FileName="httpserverapp/Utils.h" Line="47" Column="57" />
1010
<File FileName="httpserverapp/Test.h" Line="1" Column="1" />
11-
<File FileName="httpserverapp/Test.cpp" Line="1" Column="1" />
11+
<File FileName="httpserverapp/Test.cpp" Line="13" Column="2" />
1212
<File FileName="httpserverapp/Socket.h" Line="1" Column="1" />
13-
<File FileName="httpserverapp/Utils.cpp" Line="245" Column="3" />
13+
<File FileName="httpserverapp/Utils.cpp" Line="22" Column="2" />
1414
<File FileName="httpserverapp/Socket.cpp" Line="1" Column="1" />
1515
<File FileName="httpserverapp/System.h" Line="1" Column="1" />
1616
<File FileName="httpserverapp/RawData.h" Line="1" Column="1" />

httpserverapp/Main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ DLLEXPORT int application_call(HttpServer::server_request *request, HttpServer::
6868
return result;
6969
}
7070

71+
DLLEXPORT void application_clear(Utils::raw_pair headers[], const size_t headers_count)
72+
{
73+
if (headers && headers_count)
74+
{
75+
destroyRawPairs(headers, headers_count);
76+
}
77+
}
78+
7179
DLLEXPORT void application_final()
7280
{
7381

httpserverapp/Test.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,8 @@ bool test(HttpServer::ServerRequest &request, HttpServer::ServerResponse &respon
99
HttpServer::Socket &socket = response.socket;
1010
std::map<std::string, std::string> &headers_outgoing = response.headers;
1111

12-
headers_outgoing[""] = "HTTP/1.1 200 OK";
13-
headers_outgoing["Content-Type"] = "text/html; charset=utf-8";
14-
headers_outgoing["Connection"] = "keep-alive";
15-
// headers_outgoing["Content-Type"] = "text/plain; charset=utf-8";
16-
// headers_outgoing["Access-Control-Allow-Origin"] = "*";
17-
18-
size_t write_len;
19-
2012
std::string s;
2113

22-
// write_len = socket.send(s);
23-
24-
// s.clear();
25-
2614
for (auto h = incoming_headers.cbegin(); h != incoming_headers.cend(); ++h)
2715
{
2816
s += h->first + ":" + h->second + "\n";
@@ -35,7 +23,7 @@ bool test(HttpServer::ServerRequest &request, HttpServer::ServerResponse &respon
3523
s += v->first + ": " + v->second + "\n";
3624
}
3725

38-
s = "\
26+
/* s = "\
3927
<table width=\"100%\">\
4028
<tr>\
4129
<td>1<td>\
@@ -45,9 +33,15 @@ bool test(HttpServer::ServerRequest &request, HttpServer::ServerResponse &respon
4533
<td>3<td>\
4634
<td>4<td>\
4735
</tr>\
48-
</table>";
36+
</table>";*/
4937

38+
headers_outgoing[""] = "HTTP/1.1 200 OK";
39+
headers_outgoing["Content-Type"] = "text/plain; charset=utf-8";
40+
// headers_outgoing["Access-Control-Allow-Origin"] = "*";
41+
// headers_outgoing["Content-Type"] = "text/html; charset=utf-8";
5042
headers_outgoing["Content-Length"] = std::to_string(s.length() );
43+
headers_outgoing["Connection"] = "keep-alive";
44+
headers_outgoing["Date"] = Utils::getDatetimeStringValue();
5145

5246
std::string headers;
5347

@@ -65,10 +59,16 @@ bool test(HttpServer::ServerRequest &request, HttpServer::ServerResponse &respon
6559

6660
headers_outgoing.clear();
6761

68-
s = headers + s;
62+
// s = headers + s;
6963

7064
std::chrono::milliseconds timeout(5000);
71-
write_len = socket.nonblock_send(s, timeout);
65+
66+
socket.nonblock_send(headers, timeout);
67+
68+
if ( (size_t)~0 == socket.nonblock_send(s, timeout) )
69+
{
70+
socket.close();
71+
}
7272

7373
return EXIT_SUCCESS;
7474
}

httpserverapp/Test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "ServerRequest.h"
44
#include "ServerResponse.h"
55

6+
#include "Utils.h"
7+
68
#include <cstdlib>
79

810
bool test(HttpServer::ServerRequest &, HttpServer::ServerResponse &);

0 commit comments

Comments
 (0)