Skip to content

Commit e144007

Browse files
committed
Merge branch 'master' of git://github.com/cpp-netlib/cpp-netlib into cpp-netlib-master
Conflicts: .gitignore
2 parents 2b8dfc1 + 49d3b20 commit e144007

File tree

12 files changed

+258
-69
lines changed

12 files changed

+258
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ _build
1313
CPP-NETLIB.*
1414
CMakeScripts/
1515
*.cmake
16+
*~

Jamroot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import os ;
88

9-
local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
9+
path-constant BOOST_ROOT : [ os.environ BOOST_ROOT ] ;
1010

1111
use-project /boost : $(BOOST_ROOT) ;
1212
use-project /cpp-netlib : libs/network/build ;

include/network/message/wrappers/source.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
namespace network {
1313

1414
struct source_wrapper {
15-
explicit source_wrapper(message_base & message);
15+
explicit source_wrapper(message_base const & message);
1616
operator std::string () const;
1717
private:
18-
message_base & message_;
18+
message_base const & message_;
1919
mutable boost::optional<std::string> cache_;
2020
};
2121

2222
inline source_wrapper const
23-
source(message_base & message_) {
23+
source(message_base const & message_) {
2424
return source_wrapper(message_);
2525
}
2626

include/network/message/wrappers/source.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace network {
1313

14-
source_wrapper::source_wrapper(message_base & message):
14+
source_wrapper::source_wrapper(message_base const & message):
1515
message_(message) {}
1616

1717
source_wrapper::operator std::string () const {

include/network/protocol/http/client/connection/async_normal.ipp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,44 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
430430
placeholders::bytes_transferred)));
431431
} else {
432432
NETWORK_MESSAGE("no callback provided, appending to body...");
433+
bool get_more = true;
434+
if (content_length_) {
435+
buffer_type::const_iterator begin = this->part.begin();
436+
buffer_type::const_iterator end = begin;
437+
std::advance(end, bytes_transferred);
438+
get_more = (end - begin) < *content_length_;
439+
NETWORK_MESSAGE("content_length = " << * content_length_
440+
<< ", bytes read = " << (end - begin) << ", read more = " << get_more);
441+
}
433442
// Here we don't have a body callback. Let's
434443
// make sure that we deal with the remainder
435444
// from the headers part in case we do have data
436445
// that's still in the buffer.
437-
this->parse_body(request_strand_.wrap(
438-
boost::bind(
439-
&this_type::handle_received_data,
440-
this_type::shared_from_this(),
441-
body,
442-
get_body,
443-
callback,
444-
placeholders::error,
445-
placeholders::bytes_transferred)),
446-
bytes_transferred);
446+
if (get_more) {
447+
this->parse_body(request_strand_.wrap(
448+
boost::bind(
449+
&this_type::handle_received_data,
450+
this_type::shared_from_this(),
451+
body,
452+
get_body,
453+
callback,
454+
placeholders::error,
455+
placeholders::bytes_transferred)),
456+
bytes_transferred);
457+
} else {
458+
std::string body_string;
459+
std::swap(body_string, this->partial_parsed);
460+
body_string.append(
461+
this->part.begin()
462+
, bytes_transferred
463+
);
464+
this->body_promise.set_value(body_string);
465+
// TODO set the destination value somewhere!
466+
this->destination_promise.set_value("");
467+
this->source_promise.set_value("");
468+
this->part.assign('\0');
469+
this->response_parser_.reset();
470+
}
447471
}
448472
}
449473
return;
@@ -709,6 +733,21 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
709733
boost::trim(header_pair.second);
710734
headers.insert(header_pair);
711735
}
736+
// Set content length
737+
content_length_ = boost::none;
738+
auto it = headers.find("Content-Length");
739+
if (it != headers.end()) {
740+
try {
741+
content_length_ = std::stoul(it->second);
742+
NETWORK_MESSAGE("Content-Length: " << *content_length_);
743+
} catch(const std::invalid_argument&) {
744+
NETWORK_MESSAGE("invalid argument exception while interpreting "
745+
<< it->second << " as content length");
746+
} catch(const std::out_of_range&) {
747+
NETWORK_MESSAGE("out of range exception while interpreting "
748+
<< it->second << " as content length");
749+
}
750+
}
712751
headers_promise.set_value(headers);
713752
}
714753

@@ -790,6 +829,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
790829
boost::promise<boost::uint16_t> status_promise;
791830
boost::promise<std::string> status_message_promise;
792831
boost::promise<std::multimap<std::string, std::string> > headers_promise;
832+
boost::optional<size_t> content_length_;
793833
boost::promise<std::string> source_promise;
794834
boost::promise<std::string> destination_promise;
795835
boost::promise<std::string> body_promise;

include/network/protocol/http/message/header/name.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace network {
1414
namespace http {
1515

1616
template <class T1, class T2>
17-
T1 &
17+
inline T1 const &
1818
name(std::pair<T1,T2> const & p) {
1919
return p.first;
2020
}

include/network/protocol/http/message/header/value.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct request_header;
1616
struct response_header;
1717

1818
template <class T1, class T2>
19-
T1 & value(std::pair<T1,T2> const & p) {
19+
inline T1 const & value(std::pair<T1,T2> const & p) {
2020
return p.second;
2121
}
2222

libs/network/build/Jamfile.v2

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,77 @@
44
# (See accompanying file LICENSE_1_0.txt or copy at
55
# http://www.boost.org/LICENSE_1_0.txt)
66

7-
import os ;
8-
9-
local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
7+
import pch ;
108

119
project cpp-netlib :
1210
requirements
13-
<include>../../../
11+
<variant>debug:<define>NETWORK_DEBUG
12+
<toolset>gcc:<define>NETWORK_ENABLE_HTTPS
13+
<toolset>gcc:<cxxflags>-std=c++0x
14+
<include>../../../include
1415
<include>$(BOOST_ROOT)
1516
<c++-template-depth>256
17+
<link>static
1618
: source-location ../../../
1719
;
1820

19-
cpp-pch client : boost/network/include/http/client.hpp ;
20-
cpp-pch server : boost/network/include/http/server.hpp ;
21-
lib cppnetlib-uri : libs/network/src/uri/parse.cpp ;
22-
lib cppnetlib-server-parsers : libs/network/src/server_request_parsers_impl.cpp ;
23-
lib cppnetlib-client-connections : libs/network/src/client.cpp ;
21+
cpp-pch client : include/network/include/http/client.hpp ;
22+
cpp-pch server : include/network/include/http/server.hpp ;
23+
lib cppnetlib-uri : libs/network/src/uri/normalize.cpp
24+
libs/network/src/uri/schemes.cpp
25+
libs/network/src/uri/uri.cpp ;
26+
27+
lib cppnetlib-message : libs/network/src/message/message.cpp cppnetlib-uri ;
28+
lib cppnetlib-message-directives : libs/network/src/message/directives.cpp ;
29+
lib cppnetlib-message-wrappers : libs/network/src/message/wrappers.cpp ;
30+
lib cppnetlib-http-message : libs/network/src/http/request.cpp
31+
libs/network/src/http/response.cpp
32+
cppnetlib-message ;
33+
34+
lib cppnetlib-http-message-wrappers : libs/network/src/http/message/wrappers.cpp ;
35+
lib cppnetlib-http-server-parsers : libs/network/src/server_request_parsers_impl.cpp ;
36+
lib cppnetlib-http-server : libs/network/src/http/server_async_impl.cpp
37+
libs/network/src/http/server_options.cpp
38+
libs/network/src/http/server_socket_options_setter.cpp
39+
libs/network/src/http/server_sync_impl.cpp
40+
cppnetlib-constants
41+
cppnetlib-uri
42+
cppnetlib-message
43+
cppnetlib-message-wrappers
44+
cppnetlib-message-directives
45+
cppnetlib-http-message
46+
cppnetlib-http-message-wrappers
47+
cppnetlib-http-server-parsers ;
48+
49+
lib cppnetlib-http-client-connections : libs/network/src/http/client_connections.cpp
50+
libs/network/src/http/simple_connection_manager.cpp
51+
libs/network/src/http/simple_connection_factory.cpp
52+
libs/network/src/http/connection_delegate_factory.cpp
53+
libs/network/src/http/client_resolver_delegate.cpp
54+
libs/network/src/http/client_resolver_delegate_factory.cpp
55+
libs/network/src/http/client_connection_delegates.cpp
56+
libs/network/src/http/client_connection_factory.cpp
57+
libs/network/src/http/client_async_resolver.cpp
58+
libs/network/src/http/client_connection_normal.cpp ;
59+
60+
lib cppnetlib-http-client : libs/network/src/http/client.cpp
61+
cppnetlib-constants
62+
cppnetlib-uri
63+
cppnetlib-message
64+
cppnetlib-message-wrappers
65+
cppnetlib-message-directives
66+
cppnetlib-http-message
67+
cppnetlib-http-message-wrappers
68+
cppnetlib-http-client-connections ;
69+
70+
lib cppnetlib-utils-thread_pool : libs/network/src/utils/thread_pool.cpp ;
71+
lib cppnetlib-constants : libs/network/src/constants.cpp ;
2472

2573
install headers : client server
2674
: <location>../../../boost/network/include/http ;
2775

28-
install libraries : cppnetlib-uri cppnetlib-server-parsers cppnetlib-client-connections ;
76+
install libraries : cppnetlib-uri cppnetlib-message cppnetlib-message-directives cppnetlib-message-wrappers
77+
cppnetlib-http-message cppnetlib-http-message-wrappers cppnetlib-http-server-parsers cppnetlib-http-server
78+
cppnetlib-http-client-connections cppnetlib-http-client cppnetlib-utils-thread_pool cppnetlib-constants ;
2979

3080
alias all : headers ;

libs/network/test/Jamfile.v2

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
# Copyright Dean Michael Berris 2007.
33
# Distributed under the Boost Software License, Version 1.0.
44
# (See accompanying file LICENSE_1_0.txt or copy at
@@ -15,24 +15,23 @@ if [ os.name ] = CYGWIN
1515

1616
project network_test :
1717
requirements
18-
<include>../../../
19-
<include>.
18+
<include>../../../include
2019
<source>/boost//unit_test_framework
2120
<source>/boost//system
2221
<source>/boost//date_time
2322
<source>/boost//regex
2423
<source>/boost//thread
2524
<source>/boost//filesystem
26-
<variant>debug:<define>BOOST_NETWORK_DEBUG
27-
<toolset>gcc:<define>BOOST_NETWORK_ENABLE_HTTPS
25+
<variant>debug:<define>NETWORK_DEBUG
26+
<toolset>gcc:<define>NETWORK_ENABLE_HTTPS
2827
<toolset>gcc:<linkflags>-lpthread
2928
<toolset>gcc:<linkflags>-lssl
3029
<toolset>gcc:<linkflags>-lcrypto
31-
<toolset>darwin:<define>BOOST_NETWORK_ENABLE_HTTPS
30+
<toolset>darwin:<define>NETWORK_ENABLE_HTTPS
3231
<toolset>darwin:<linkflags>-lpthread
3332
<toolset>darwin:<linkflags>-lssl
3433
<toolset>darwin:<linkflags>-lcrypto
35-
<toolset>clang:<define>BOOST_NETWORK_ENABLE_HTTPS
34+
<toolset>clang:<define>NETWORK_ENABLE_HTTPS
3635
<toolset>clang:<linkflags>-lpthread
3736
<toolset>clang:<linkflags>-lssl
3837
<toolset>clang:<linkflags>-lcrypto
@@ -43,13 +42,19 @@ project network_test :
4342
<toolset>msvc:<define>BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
4443
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
4544
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
46-
<toolset>msvc:<define>_WIN32_WINNT=0x0501
45+
<toolset>msvc:<define>_WIN32_WINNT=0x0501
4746
<c++-template-depth>256
4847
<link>static
4948
;
5049

5150
build-project http ;
5251
build-project uri ;
5352

54-
run message_test.cpp ;
55-
run message_transform_test.cpp ;
53+
run message_test.cpp /cpp-netlib//cppnetlib-message
54+
/cpp-netlib//cppnetlib-message-directives
55+
/cpp-netlib//cppnetlib-message-wrappers ;
56+
57+
run message_transform_test.cpp /cpp-netlib//cppnetlib-message
58+
/cpp-netlib//cppnetlib-message-directives
59+
/cpp-netlib//cppnetlib-message-wrappers ;
60+

0 commit comments

Comments
 (0)