FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
libhttpserver/examples/Test.cpp at examples · MPursche/libhttpserver · GitHub
MPursche
/
libhttpserver
Public
forked from
etr/libhttpserver
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
libhttpserver
/
examples
/
Test.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (84 loc) · 2.75 KB
Breadcrumbs
libhttpserver
/
examples
/
Test.cpp
Copy path
File metadata and controls
92 lines (84 loc) · 2.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#
include
"
Test.hpp
"
#
include
<
signal.h
>
#
include
<
string
>
#
include
<
vector
>
#
include
<
unistd.h
>
#
include
<
iostream
>
#
include
<
fstream
>
#
include
<
stdio.h
>
using
namespace
std
;
webserver* ws_ptr;
/*
void signal_callback_handler(int signum)
{
cout << "bye!" << endl;
ws_ptr->stop();
}
*/
Test::Test
() : http_resource()
{
}
Test2::Test2
() : http_resource()
{
}
http_response
Test::render_GET
(
const
http_request& r)
{
/*
cout << r.get_version() << endl;
cout << r.get_requestor() << endl;
cout << r.get_requestor_port() << endl;
cout << "PROVA: " << r.get_arg("prova") << endl;
cout << "ALTRO: " << r.get_arg("altro") << endl;
cout << "THUMB: " << r.get_arg("thumbId") << endl;
cout << "COOKIE: " << r.get_cookie("auth") << endl;
std::map<std::string, std::string, header_comparator> head;
r.get_headers(head);
for(std::map<std::string, std::string, header_comparator>::const_iterator it = head.begin(); it != head.end(); ++it)
cout << (*it).first << "-> " << (*it).second << endl;
string pp = r.get_arg("prova");
*/
std::vector<std::string> topics;
topics.
push_back
(
"
prova
"
);
//
return long_polling_receive_response("", 200, "", topics, 10, "keepalive\n");
cout << r.
get_querystring
() << endl;
return
http_file_response
(
"
/home/etr/progs/libhttpserver/test/noimg.png
"
,
200
,
"
image/png
"
);
}
http_response
Test::render_POST
(
const
http_request& r)
{
/*
fstream filestr;
filestr.open("test.txt", fstream::out | fstream::app);
filestr << r.get_content() << endl;
filestr.close();
cout << "DOPO" << endl;
vector<string> vv = r.get_path_pieces();
for(int i = 0; i < vv.size(); i++)
{
cout << vv[i] << endl;
}
return http_string_response("OK",200);
*/
http_string_response
s
(
"
OK
"
,
200
);
s.
set_header
(http_utils::http_header_location,
"
B
"
);
return
s;
//
return long_polling_send_response("<script type=\"text/javascript\">alert(\"ciao\")</script>\n", "prova");
}
http_response
Test2::render_GET
(
const
http_request& r)
{
cout <<
"
D2
"
<< endl;
return
http_string_response
(
"
{
\"
var1
\"
:
\"
"
+r.
get_arg
(
"
var1
"
)+
"
\"
,
\"
var2
\"
:
\"
"
+r.
get_arg
(
"
var2
"
)+
"
\"
,
\"
var3
\"
:
\"
"
+r.
get_arg
(
"
var3
"
)+
"
\"
}
"
,
200
);
}
http_response
Test::render_PUT
(
const
http_request& r)
{
return
http_string_response
(r.
get_content
(),
200
);
}
int
main
()
{
//
signal(SIGINT, &signal_callback_handler);
webserver ws =
create_webserver
(
8080
);
ws_ptr = &ws;
Test dt =
Test
();
Test2 dt2 =
Test2
();
ws.
register_resource
(
string
(
"
base/{var1}/{var2}/drop_test/{var3}/tail
"
), &dt2,
true
);
ws.
register_resource
(
string
(
"
other/side/{thumbId|[0-9]*}
"
), &dt,
true
);
ws.
register_resource
(
string
(
"
another/{thumbId|[0-9]*}
"
), &dt,
true
);
ws.
register_resource
(
string
(
"
edge/thumbnail
"
), &dt,
true
);
ws.
start
(
true
);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL