Skip to content

Commit 70a99a9

Browse files
committed
Added a message_base class.
1 parent 73b0831 commit 70a99a9

File tree

6 files changed

+112
-47
lines changed

6 files changed

+112
-47
lines changed

http/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
include_directories(
11+
${CPP-NETLIB_SOURCE_DIR}/config/src
1112
${CPP-NETLIB_SOURCE_DIR}/uri/src
1213
${CPP-NETLIB_SOURCE_DIR}/message/src
1314
${CPP-NETLIB_SOURCE_DIR}/logging/src

http/src/network/http/v2/client/byte_source.hpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

http/src/network/http/v2/client/request.hpp

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,68 @@
88

99
#include <cstdint>
1010
#include <memory>
11-
#include <network/uri.hpp>
12-
#include <network/http/v2/client/byte_source.hpp>
11+
#include <string>
12+
#include <network/http/v2/message_base.hpp>
13+
#include <network/http/v2/url.hpp>
1314

1415
namespace network {
1516
namespace http {
1617
namespace v2 {
18+
class byte_source {
19+
20+
public:
21+
22+
typedef message_base::string_type string_type;
23+
typedef message_base::size_type size_type;
24+
25+
virtual ~byte_source() {}
26+
27+
virtual size_type read(string_type &source, size_type length) = 0;
28+
29+
};
30+
31+
class string_byte_source : public byte_source {
32+
33+
public:
34+
35+
explicit string_byte_source(string_type source);
36+
37+
virtual ~string_byte_source() {}
38+
39+
virtual size_type read(string_type &source, size_type length);
40+
41+
private:
42+
43+
string_type source_;
44+
45+
};
46+
1747
class request {
1848

49+
typedef byte_source::string_type string_type;
50+
1951
public:
2052

21-
request(uri locator, std::shared_ptr<byte_source> = nullptr)
22-
: locator_(locator) { }
53+
request(url locator, std::shared_ptr<byte_source> source = nullptr)
54+
: locator_(locator), source_(source) { }
55+
56+
request(const request &other)
57+
: locator_(other.locator_), source_(other.source_) { }
58+
59+
request(request &&other) noexcept
60+
: locator_(std::move(other.locator_)), source_(std::move(other.source_)) { }
61+
62+
request &operator = (request other) {
63+
other.swap(*this);
64+
return *this;
65+
}
66+
67+
void swap(request &other) noexcept {
68+
locator_.swap(other.locator_);
69+
source_.swap(other.source_);
70+
}
2371

24-
// destination
72+
void set_destination(string_type destination);
2573
// source
2674
// add_header
2775
// remove_header
@@ -36,7 +84,7 @@ namespace v2 {
3684
// uri
3785
// version
3886

39-
uri locator_;
87+
url locator_;
4088
std::shared_ptr<byte_source> source_;
4189

4290
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (C) 2013 by Glyn Matthews
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#ifndef __NETWORK_HTTP_V2_MESSAGE_BASE_INC__
7+
#define __NETWORK_HTTP_V2_MESSAGE_BASE_INC__
8+
9+
#include <network/config.hpp>
10+
#include <network/uri.hpp>
11+
#include <string>
12+
#include <functional>
13+
14+
namespace network {
15+
namespace http {
16+
class message_base {
17+
18+
public:
19+
20+
typedef std::string string_type;
21+
typedef string_type::size_type size_type;
22+
23+
message_base() NETWORK_DEFAULTED_FUNCTION;
24+
25+
message_base(const message_base &) NETWORK_DELETED_FUNCTION;
26+
27+
message_base &operator = (const message_base &) NETWORK_DELETED_FUNCTION;
28+
29+
virtual ~message_base() NETWORK_NOEXCEPT = 0;
30+
31+
// Mutators
32+
virtual void set_destination(string_type destination) = 0;
33+
virtual void set_source(string_type source) = 0;
34+
virtual void append_header(string_type name, string_type value) = 0;
35+
virtual void remove_headers(string_type name) = 0;
36+
virtual void clear_headers() = 0;
37+
virtual void set_body(std::string body) = 0;
38+
virtual void append_body(std::string data) = 0;
39+
40+
// Accessors
41+
virtual string_type destination() const = 0;
42+
virtual string_type source() = 0;
43+
virtual string_type headers(std::function<void (string_type, string_type)> inserter) const = 0;
44+
virtual string_type headers(std::function<bool (string_type, string_type)> predicate,
45+
std::function<void (string_type, string_type)> inserter) const = 0;
46+
virtual string_type body() const = 0;
47+
virtual void body(std::function<void (string_type::const_iterator, size_type)> chunk_reader,
48+
size_type size) = 0;
49+
50+
};
51+
} // namespace v2
52+
} // namespace network
53+
54+
55+
#endif // __NETWORK_HTTP_V2_MESSAGE_BASE_INC__

http/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# http://www.boost.org/LICENSE_1_0.txt)
66

77
include_directories(
8+
${CPP-NETLIB_SOURCE_DIR}/config/src
89
${CPP-NETLIB_SOURCE_DIR}/uri/src
910
${CPP-NETLIB_SOURCE_DIR}/message/src
1011
${CPP-NETLIB_SOURCE_DIR}/logging/src

http/test/v2/client/byte_source_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include <gtest/gtest.h>
7-
#include <network/http/v2/client/byte_source.hpp>
7+
#include <network/http/v2/client/request.hpp>
88

99

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy