• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-server / 42510611165

08 Nov 2026 06:33PM UTC coverage: 94.917% (+0.06%) from 94.853%
42510611165

push

github

web-flow
Merge pull request #1130 from evoskuil/master

Stream blocks to socket buffer, rename zmq, drop cuda ecc if nocuda.

107 of 112 new or added lines in 16 files covered. (95.54%)

12063 of 12709 relevant lines covered (94.92%)

241.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.1
/src/protocols/protocol_http.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/server/protocols/protocol_http.hpp>
20

21
#include <bitcoin/server/define.hpp>
22

23
namespace libbitcoin {
24
namespace server {
25

26
#define CLASS protocol_http
27

28
using namespace network::http;
29
using namespace std::placeholders;
30

31
// Shared pointers required in handler parameters so closures control lifetime.
32
BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
33
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
34

35
// Websocket dispatch.
36
// ----------------------------------------------------------------------------
37

38
void protocol_http::handle_receive_websocket(const code& ec,
11,189 ✔
39
    const method::websocket::cptr& websocket) NOEXCEPT
40
{
41
    BC_ASSERT(stranded());
11,189 ✔
42

43
    if (stopped(ec))
11,189 ✔
44
        return;
45

46
    dispatch_websocket(*websocket);
1,791 ✔
47
}
48

49
void protocol_http::handle_receive_stream(const code& ec,
10,726 ✔
50
    const method::stream::cptr& stream) NOEXCEPT
51
{
52
    BC_ASSERT(stranded());
10,726 ✔
53

54
    if (stopped(ec))
10,726 ✔
55
        return;
56

57
    dispatch_websocket(*stream);
1,325 ✔
58
}
59

60
void protocol_http::dispatch_websocket(const request& ) NOEXCEPT
×
61
{
62
    BC_ASSERT(stranded());
×
63
    stop(error::not_implemented);
×
64
}
×
65

66
// Caching for http response abstraction.
67
// ----------------------------------------------------------------------------
68

69
// Cache request for serialization, keeping it out of dispatch.
70
void protocol_http::set_request(const request_cptr& request) NOEXCEPT
680 ✔
71
{
72
    ////BC_ASSERT(stranded());
73
    BC_ASSERT(request);
680 ✔
74
    request_ = request;
680 ✔
75
}
680 ✔
76

77
// Returns default if not set, for safety (asserts correctness).
78
request_cptr protocol_http::reset_request() NOEXCEPT
643 ✔
79
{
80
    ////BC_ASSERT(stranded());
81
    BC_ASSERT(request_);
643 ✔
82

83
    if (request_)
84
    {
85
        auto copy = request_;
643 ✔
86
        request_.reset();
643 ✔
87
        return copy;
643 ✔
88
    }
643 ✔
89

90
    return system::to_shared<request>();
91
}
92

93
const request_cptr& protocol_http::get_request() const NOEXCEPT
6 ✔
94
{
95
    ////BC_ASSERT(stranded());
96
    return request_;
6 ✔
97
}
98

99
// Streaming response.
100
// ----------------------------------------------------------------------------
101

102
void protocol_http::send_stream(size_t size, wire_writer&& writer,
13 ✔
103
    media_type type, const request& request) NOEXCEPT
104
{
105
    BC_ASSERT(stranded());
13 ✔
106
    response message{ status::ok, request.version() };
13 ✔
107
    add_common_headers(message, request);
13 ✔
108
    add_access_control_headers(message, request);
13 ✔
109
    message.set(field::content_type, from_media_type(type));
13 ✔
110
    message.body() = stream_value
13 ✔
111
    {
112
        .write = std::move(writer),
13 ✔
113
        .size = size
114
    };
13 ✔
115
    message.prepare_payload();
13 ✔
116
    SEND(std::move(message), handle_stream, _1);
13 ✔
117
}
13 ✔
118

119
// A stream body write fails as unexpected only when its writer fails.
120
void protocol_http::handle_stream(const code& ec) NOEXCEPT
13 ✔
121
{
122
    BC_ASSERT(stranded());
13 ✔
123
    if (ec == network::error::unexpected_body)
13 ✔
NEW
124
        fault(database::error::integrity);
×
125

126
    handle_complete(ec, network::error::success);
13 ✔
127
}
13 ✔
128

129
BC_POP_WARNING()
130
BC_POP_WARNING()
131

132
} // namespace server
133
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc