Skip to content

Commit 2c6bc4c

Browse files
committed
Merge branch '0.5-devel' of git://github.com/glynos/cpp-netlib into 0.5-devel
2 parents 974cd12 + f1e8d68 commit 2c6bc4c

14 files changed

+235
-184
lines changed

libs/network/doc/Jamfile.v2

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ boostbook standalone
2525
# How far down we go with TOC's
2626
<xsl:param>generate.section.toc.level=10
2727
# Path for links to Boost:
28-
<xsl:param>boost.root=http://www.boost.org
28+
<xsl:param>boost.root=http://glynos.github.com/cpp-netlib
2929
# Path for libraries index:
3030
<xsl:param>boost.libraries=http://www.boost.org/libs/libraries.htm
3131
# Use the main Boost stylesheet:

libs/network/doc/boostbook.css

+14-4
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@
116116
h1 tt.computeroutput { font-size: 140% }
117117
h2 tt.computeroutput { font-size: 140% }
118118
h3 tt.computeroutput { font-size: 130% }
119-
h4 tt.computeroutput { font-size: 120% }
120-
h5 tt.computeroutput { font-size: 110% }
121-
h6 tt.computeroutput { font-size: 100% }
119+
h4 tt.computeroutput { font-size: 130% }
120+
h5 tt.computeroutput { font-size: 130% }
121+
h6 tt.computeroutput { font-size: 130% }
122+
122123

123124
/*=============================================================================
124125
Author
@@ -217,7 +218,10 @@
217218
float: right;
218219
padding: 0.5pc;
219220
}
220-
221+
222+
/* Code on toc */
223+
.toc .computeroutput { font-size: 120% }
224+
221225
/*=============================================================================
222226
Tables
223227
=============================================================================*/
@@ -304,6 +308,11 @@
304308
Variable Lists
305309
=============================================================================*/
306310

311+
div.variablelist
312+
{
313+
margin: 1em 0;
314+
}
315+
307316
/* Make the terms in definition lists bold */
308317
div.variablelist dl dt,
309318
span.term
@@ -374,6 +383,7 @@
374383
{
375384
body {
376385
background-color: #FFFFFF;
386+
color: #000000;
377387
}
378388

379389
/* Links */

libs/network/doc/examples.qbk

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
[section:examples Examples]
10-
[include examples/hello_world.qbk]
11-
[include examples/http_client.qbk]
10+
[/ include examples/hello_world.qbk]
11+
[/ include examples/http_client.qbk]
1212
[include examples/simple_wget.qbk]
1313
[endsect]

libs/network/doc/http.qbk

+146-57
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,130 @@
77

88

99
[section:http HTTP]
10-
The __cnl__ provides direct support for HTTP. As a motivating
11-
example, here is the code again from the __quick_start__.
1210

13-
#include <boost/network/protocol/http.hpp>
11+
[section:http_server_example HTTP Server]
12+
13+
Here is the server code again from the __quick_start__.
14+
15+
``
16+
#include <boost/network/protocol/http/server.hpp>
1417
#include <iostream>
18+
19+
20+
namespace http = boost::network::http;
21+
22+
23+
struct hello_world;
24+
typedef http::server<hello_world> server;
25+
26+
struct hello_world {
27+
void operator() (server::request const &request,
28+
server::response &response) {
29+
response = server::response::stock_reply(
30+
server::response::ok, "Hello, World!");
31+
}
32+
void log(...) {
33+
// do nothing
34+
}
35+
};
36+
37+
38+
int main(int argc, char * argv[]) {
39+
40+
if (argc != 3) {
41+
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
42+
return 1;
43+
}
44+
45+
try {
46+
hello_world handler;
47+
http::server<hello_world> server_(argv[1], argv[2], handler);
48+
server_.run();
49+
}
50+
catch (std::exception &e) {
51+
std::cerr << e.what() << std::endl;
52+
return 1;
53+
}
54+
55+
return 0;
56+
}
57+
``
58+
59+
[heading HTTP Server]
60+
61+
namespace boost { namespace network { namespace http {
62+
template <class Tag, class Handler> class basic_server;
63+
}}}
64+
65+
The `server` encapsulates the server side connections, manages the
66+
incoming data and can be configured to handle incoming requests.
67+
68+
[heading HTTP Request Handler]
69+
70+
struct hello_world {
71+
void operator() (server::request const &request,
72+
server::response &response) {
73+
response = server::response::stock_reply(
74+
server::response::ok, "Hello, World!");
75+
}
76+
void log(...) {
77+
// do nothing
78+
}
79+
};
1580

81+
The request handler is a functor class that accepts as an argument an
82+
incoming request and an outgoing response. An additional `log` member
83+
function is also required to be defined.
84+
85+
[heading Running the Server]
86+
87+
hello_world handler;
88+
http::server<hello_world> server_(argv[1], argv[2], handler);
89+
server_.run();
90+
91+
The `hello_world` request handler is given as a template argument to
92+
`http::server`. The first two constructor arguments are the address
93+
and port, and the `hello_world` handler object is passed as the third
94+
argument.
95+
96+
[endsect] [/ http_server_example]
97+
98+
[section:http_client_example HTTP Client]
99+
100+
Here is the client code again from the __quick_start__.
101+
102+
``
103+
#include <boost/network/protocol/http/client.hpp>
104+
#include <iostream>
105+
106+
107+
namespace http = boost::network::http;
108+
109+
16110
int
17111
main(int argc, char *argv[]) {
18-
using boost::network;
19-
20-
http::request request("http://www.boost.org/");
21-
http::client client;
22-
http::response response = client.get(request);
23-
24-
// print response headers
25-
headers_range<http::response>::type hdrs = headers(response);
26-
boost::range_iterator<headers_range<http::response>::type>::type
27-
it = boost::begin(hdrs), end = boost::end(hdrs);
28-
for (; it != end; ++it) {
29-
std::cout << it->first << ": " << it->second << std::endl;
112+
if (argc != 2) {
113+
std::cerr << "Usage: " << argv[0] << " url" << std::endl;
114+
return 1;
30115
}
31-
32-
// print response body
33-
std::cout << body(response) << std::endl;
116+
117+
try {
118+
http::client client;
119+
http::client::request request(argv[1]);
120+
http::client::response response = client.get(request);
121+
std::cout << boost::network::body(response) << std::endl;
122+
}
123+
catch (std::exception &e) {
124+
std::cerr << e.what() << std::endl;
125+
return 1;
126+
}
127+
34128
return 0;
35129
}
130+
``
36131

37132
Before walking through exactly what is happening in this example, the
38-
principle components are described below:
133+
principal components are described below:
39134

40135
[heading HTTP Request]
41136

@@ -44,7 +139,7 @@ principle components are described below:
44139
typedef basic_request<tags::default_> request;
45140
}}}
46141

47-
The [^request] encapsulates information about the request and the
142+
The `request` encapsulates information about the request and the
48143
resource. It models the Message concept.
49144

50145
[heading HTTP Client]
@@ -54,9 +149,9 @@ resource. It models the Message concept.
54149
typedef basic_client<tags::default_> client;
55150
}}}
56151

57-
The [^client] encapsulates the connection-mapping logic between the
152+
The `client` encapsulates the connection-mapping logic between the
58153
domain and the underlying socket. Access to a resource is managed
59-
through the [^client] object.
154+
through the `client` object.
60155

61156
[heading HTTP Response]
62157

@@ -65,75 +160,69 @@ through the [^client] object.
65160
typedef basic_response<tags::default_> response;
66161
}}}
67162

68-
The [^response] encapsulates the data received from the server. It
163+
The `response` encapsulates the data received from the server. It
69164
also models the Message concept.
70165

71-
[heading Walkthrough]
72-
73-
http::request request("http://www.boost.org/");
74-
75-
This line frames the request for the resource __boost_org__.
166+
[heading HTTP Client Walkthrough]
76167

77168
http::client client;
78169

79170
Then a client object is created that handles all HTTP requests and
80171
responses.
81172

173+
http::request request(argv[1]);
174+
175+
This line frames the request for the resource given as a command line
176+
argument.
177+
82178
http::response response = client.get(request);
83179

84180
The client simply performs the requests. The interface is trivially
85181
easy. All HTTP methods are supported (HEAD, GET, POST, PUT, DELETE).
86182

87183
There are several advantages to this design:
88184

89-
# A [^client] object manages the connection, unencumbering the
185+
# A `client` object manages the connection, unencumbering the
90186
developer with this task;
91-
# A [^request] can be used with any instance of the [^client] without
92-
binding the [^client] to any destination;
93-
# By decoupling the method from the [^request] object it allows
187+
# A `request` can be used with any instance of the `client` without
188+
binding the `client` to any destination;
189+
# By decoupling the method from the `request` object it allows
94190
developers to create requests that may be re-used (e.g. perform a
95191
HEAD first; if the the headers don't fulfil a certain criteria,
96192
perform a GET using the same resource).
97193

98-
// print response headers
99-
headers_range<http::response>::type hdrs = headers(response);
100-
boost::range_iterator<headers_range<http::response>::type>::type
101-
it = boost::begin(hdrs), end = boost::end(hdrs);
102-
for (; it != end; ++it)
103-
std::cout << it->first << ": " << it->second << std::endl;
104-
}
105-
106-
// print response body
107194
std::cout << body(response) << std::endl;
108195

109-
Once the request has been made, and the [^client] returns a
110-
[^response] object, the rest is simple. This example outputs all the
111-
response headers and body, in this case just the Boost homepage.
196+
Once the request has been made, and the `client` returns a
197+
`response` object, the rest is simple. This example outputs the
198+
response body.
112199

113-
[heading Using [^http::client]]
200+
[heading Using `http::client`]
114201

115-
The [^http::client] supports the following operations:
202+
The `http::client` supports the following operations:
116203

117-
* [^http::client::head]
118-
* [^http::client::get]
119-
* [^http::client::post]
120-
* [^http::client::put]
121-
* [^http::client::delete_]
204+
* `http::client::head`
205+
* `http::client::get`
206+
* `http::client::post`
207+
* `http::client::put`
208+
* `http::client::delete_`
122209

123210
HTTP features can be enabled by using constructor arguments:
124211

125-
* [^http::client(http::client::cache_resolved)]
126-
* [^http::client(http::client::follow_redirect)]
212+
* `http::client(http::client::cache_resolved)`
213+
* `http::client(http::client::follow_redirect)`
127214

128-
[h5 [^http::client::cache_resolved]]
215+
[h5 `http::client::cache_resolved`]
129216
This argument enables the caching of resolved endpoints and prevents
130217
the client from resolving IP addresses of previously resolved
131218
hostnames.
132219

133-
[h5 [^http::client::follow_redirect(s)]]
134-
[^http::client::follow_redirects] / [^http::client::follow_redirect]
220+
[h5 `http::client::follow_redirect(s)`]
221+
`http::client::follow_redirects` / `http::client::follow_redirect`
135222
follow HTTP redirect(s) (300..307) by looking at the "Location" header
136223
provided by the response(s); headers present in the original request
137224
are preserved in the subsequent request(s).
138225

139-
[endsect] [/http]
226+
[endsect] [/ http_client_example]
227+
228+
[endsect] [/ http]

libs/network/doc/message.qbk

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ factors such as the string encoding type or memory usage. For
3333
different reasons, its possible to assume a string implementation
3434
might be:
3535

36-
# [^std::string]
37-
# [^std::wstring]
38-
# [^std::vector<boost::uint32_t>]
39-
# [@http://msdn.microsoft.com/en-us/library/ms174288.aspx [^CString]]
40-
# [@http://doc.trolltech.com/qstring.html [^QString]]
36+
# `std::string`
37+
# `std::wstring`
38+
# `std::vector<boost::uint32_t>`
39+
# [@http://msdn.microsoft.com/en-us/library/ms174288.aspx `CString`]
40+
# [@http://doc.trolltech.com/qstring.html `QString`]
4141

4242
The __cnl__ uses tag dispatching to specialize the message interface
4343
at compile time.

libs/network/doc/network.qbk

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
[def __boost_doc__ [@http://www.boost.org/doc/libs/]]
2929
[def __pion__ [@http://www.pion.org/projects/pion-network-library the Pion Network Library]]
3030
[def __cnl__ C++ Network Library]
31-
[def __message__ [^basic_message]]
32-
[def __uri__ [^basic_uri]]
31+
[def __message__ `basic_message`]
32+
[def __uri__ `basic_uri`]
3333
[def __python__ [@http://www.python.org Python]]
3434
[def __libcurl__ [@http://curl.haxx.se/ libcurl]]
3535
[def __mozilla_netlib__ [@http://www.mozilla.org/projects/netlib/ mozilla-netlib]]

0 commit comments

Comments
 (0)