Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
444dd70d
"tools/git@developer.sourcefind.cn:OpenDAS/dlib.git" did not exist on "55c4ba531e028bdc15831557f7d328e019af7a82"
Commit
444dd70d
authored
Nov 07, 2012
by
Davis King
Browse files
Removed try/catch block since it is now redundant
parent
1db057d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
60 deletions
+52
-60
examples/server_http_ex.cpp
examples/server_http_ex.cpp
+52
-60
No files found.
examples/server_http_ex.cpp
View file @
444dd70d
...
@@ -24,70 +24,62 @@ class web_server : public server::http_1a_c
...
@@ -24,70 +24,62 @@ class web_server : public server::http_1a_c
outgoing_things
&
outgoing
outgoing_things
&
outgoing
)
)
{
{
try
ostringstream
sout
;
// We are going to send back a page that contains an HTML form with two text input fields.
// One field called name. The HTML form uses the post method but could also use the get
// method (just change method='post' to method='get').
sout
<<
" <html> <body> "
<<
"<form action='/form_handler' method='post'> "
<<
"User Name: <input name='user' type='text'><br> "
<<
"User password: <input name='pass' type='text'> <input type='submit'> "
<<
" </form>"
;
// Write out some of the inputs to this request so that they show up on the
// resulting web page.
sout
<<
"<br> path = "
<<
incoming
.
path
<<
endl
;
sout
<<
"<br> request_type = "
<<
incoming
.
request_type
<<
endl
;
sout
<<
"<br> content_type = "
<<
incoming
.
content_type
<<
endl
;
sout
<<
"<br> protocol = "
<<
incoming
.
protocol
<<
endl
;
sout
<<
"<br> foreign_ip = "
<<
incoming
.
foreign_ip
<<
endl
;
sout
<<
"<br> foreign_port = "
<<
incoming
.
foreign_port
<<
endl
;
sout
<<
"<br> local_ip = "
<<
incoming
.
local_ip
<<
endl
;
sout
<<
"<br> local_port = "
<<
incoming
.
local_port
<<
endl
;
sout
<<
"<br> body =
\"
"
<<
incoming
.
body
<<
"
\"
"
<<
endl
;
// If this request is the result of the user submitting the form then echo back
// the submission.
if
(
incoming
.
path
==
"/form_handler"
)
{
{
ostringstream
sout
;
sout
<<
"<h2> Stuff from the query string </h2>"
<<
endl
;
// We are going to send back a page that contains an HTML form with two text input fields.
sout
<<
"<br> user = "
<<
incoming
.
queries
[
"user"
]
<<
endl
;
// One field called name. The HTML form uses the post method but could also use the get
sout
<<
"<br> pass = "
<<
incoming
.
queries
[
"pass"
]
<<
endl
;
// method (just change method='post' to method='get').
sout
<<
" <html> <body> "
// save these form submissions as cookies.
<<
"<form action='/form_handler' method='post'> "
outgoing
.
cookies
[
"user"
]
=
incoming
.
queries
[
"user"
];
<<
"User Name: <input name='user' type='text'><br> "
outgoing
.
cookies
[
"pass"
]
=
incoming
.
queries
[
"pass"
];
<<
"User password: <input name='pass' type='text'> <input type='submit'> "
<<
" </form>"
;
// Write out some of the inputs to this request so that they show up on the
// resulting web page.
sout
<<
"<br> path = "
<<
incoming
.
path
<<
endl
;
sout
<<
"<br> request_type = "
<<
incoming
.
request_type
<<
endl
;
sout
<<
"<br> content_type = "
<<
incoming
.
content_type
<<
endl
;
sout
<<
"<br> protocol = "
<<
incoming
.
protocol
<<
endl
;
sout
<<
"<br> foreign_ip = "
<<
incoming
.
foreign_ip
<<
endl
;
sout
<<
"<br> foreign_port = "
<<
incoming
.
foreign_port
<<
endl
;
sout
<<
"<br> local_ip = "
<<
incoming
.
local_ip
<<
endl
;
sout
<<
"<br> local_port = "
<<
incoming
.
local_port
<<
endl
;
sout
<<
"<br> body =
\"
"
<<
incoming
.
body
<<
"
\"
"
<<
endl
;
// If this request is the result of the user submitting the form then echo back
// the submission.
if
(
incoming
.
path
==
"/form_handler"
)
{
sout
<<
"<h2> Stuff from the query string </h2>"
<<
endl
;
sout
<<
"<br> user = "
<<
incoming
.
queries
[
"user"
]
<<
endl
;
sout
<<
"<br> pass = "
<<
incoming
.
queries
[
"pass"
]
<<
endl
;
// save these form submissions as cookies.
outgoing
.
cookies
[
"user"
]
=
incoming
.
queries
[
"user"
];
outgoing
.
cookies
[
"pass"
]
=
incoming
.
queries
[
"pass"
];
}
// Echo any cookies back to the client browser
sout
<<
"<h2>Cookies the web browser sent to the server</h2>"
;
for
(
key_value_map
::
const_iterator
ci
=
incoming
.
cookies
.
begin
();
ci
!=
incoming
.
cookies
.
end
();
++
ci
)
{
sout
<<
"<br/>"
<<
ci
->
first
<<
" = "
<<
ci
->
second
<<
endl
;
}
sout
<<
"<br/><br/>"
;
sout
<<
"<h2>HTTP Headers the web browser sent to the server</h2>"
;
// Echo out all the HTTP headers we received from the client web browser
for
(
key_value_map
::
const_iterator
ci
=
incoming
.
headers
.
begin
();
ci
!=
incoming
.
headers
.
end
();
++
ci
)
{
sout
<<
"<br/>"
<<
ci
->
first
<<
": "
<<
ci
->
second
<<
endl
;
}
sout
<<
"</body> </html>"
;
return
sout
.
str
();
}
}
catch
(
exception
&
e
)
// Echo any cookies back to the client browser
sout
<<
"<h2>Cookies the web browser sent to the server</h2>"
;
for
(
key_value_map
::
const_iterator
ci
=
incoming
.
cookies
.
begin
();
ci
!=
incoming
.
cookies
.
end
();
++
ci
)
{
{
return
e
.
what
()
;
sout
<<
"<br/>"
<<
ci
->
first
<<
" = "
<<
ci
->
second
<<
endl
;
}
}
sout
<<
"<br/><br/>"
;
sout
<<
"<h2>HTTP Headers the web browser sent to the server</h2>"
;
// Echo out all the HTTP headers we received from the client web browser
for
(
key_value_map
::
const_iterator
ci
=
incoming
.
headers
.
begin
();
ci
!=
incoming
.
headers
.
end
();
++
ci
)
{
sout
<<
"<br/>"
<<
ci
->
first
<<
": "
<<
ci
->
second
<<
endl
;
}
sout
<<
"</body> </html>"
;
return
sout
.
str
();
}
}
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment