1 /*
2 * nghttp2 - HTTP/2 C Library
3 *
4 * Copyright (c) 2016 Tatsuhiro Tsujikawa
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #include "shrpx_health_monitor_downstream_connection.h"
26
27 #include "shrpx_client_handler.h"
28 #include "shrpx_upstream.h"
29 #include "shrpx_downstream.h"
30 #include "shrpx_log.h"
31
32 namespace shrpx {
33
HealthMonitorDownstreamConnection()34 HealthMonitorDownstreamConnection::HealthMonitorDownstreamConnection() {}
35
~HealthMonitorDownstreamConnection()36 HealthMonitorDownstreamConnection::~HealthMonitorDownstreamConnection() {}
37
attach_downstream(Downstream * downstream)38 int HealthMonitorDownstreamConnection::attach_downstream(
39 Downstream *downstream) {
40 if (LOG_ENABLED(INFO)) {
41 DCLOG(INFO, this) << "Attaching to DOWNSTREAM:" << downstream;
42 }
43
44 downstream_ = downstream;
45
46 return 0;
47 }
48
detach_downstream(Downstream * downstream)49 void HealthMonitorDownstreamConnection::detach_downstream(
50 Downstream *downstream) {
51 if (LOG_ENABLED(INFO)) {
52 DCLOG(INFO, this) << "Detaching from DOWNSTREAM:" << downstream;
53 }
54 downstream_ = nullptr;
55 }
56
push_request_headers()57 int HealthMonitorDownstreamConnection::push_request_headers() {
58 downstream_->set_request_header_sent(true);
59 auto src = downstream_->get_blocked_request_buf();
60 auto dest = downstream_->get_request_buf();
61 src->remove(*dest);
62
63 return 0;
64 }
65
push_upload_data_chunk(const uint8_t * data,size_t datalen)66 int HealthMonitorDownstreamConnection::push_upload_data_chunk(
67 const uint8_t *data, size_t datalen) {
68 return 0;
69 }
70
end_upload_data()71 int HealthMonitorDownstreamConnection::end_upload_data() {
72 auto upstream = downstream_->get_upstream();
73 auto &resp = downstream_->response();
74
75 resp.http_status = 200;
76
77 resp.fs.add_header_token(StringRef::from_lit("content-length"),
78 StringRef::from_lit("0"), false,
79 http2::HD_CONTENT_LENGTH);
80
81 if (upstream->send_reply(downstream_, nullptr, 0) != 0) {
82 return -1;
83 }
84
85 return 0;
86 }
87
pause_read(IOCtrlReason reason)88 void HealthMonitorDownstreamConnection::pause_read(IOCtrlReason reason) {}
89
resume_read(IOCtrlReason reason,size_t consumed)90 int HealthMonitorDownstreamConnection::resume_read(IOCtrlReason reason,
91 size_t consumed) {
92 return 0;
93 }
94
force_resume_read()95 void HealthMonitorDownstreamConnection::force_resume_read() {}
96
on_read()97 int HealthMonitorDownstreamConnection::on_read() { return 0; }
98
on_write()99 int HealthMonitorDownstreamConnection::on_write() { return 0; }
100
on_upstream_change(Upstream * upstream)101 void HealthMonitorDownstreamConnection::on_upstream_change(Upstream *upstream) {
102 }
103
poolable() const104 bool HealthMonitorDownstreamConnection::poolable() const { return false; }
105
106 const std::shared_ptr<DownstreamAddrGroup> &
get_downstream_addr_group() const107 HealthMonitorDownstreamConnection::get_downstream_addr_group() const {
108 static std::shared_ptr<DownstreamAddrGroup> s;
109 return s;
110 }
111
get_addr() const112 DownstreamAddr *HealthMonitorDownstreamConnection::get_addr() const {
113 return nullptr;
114 }
115
116 } // namespace shrpx
117