MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / readResponse

Method readResponse

extensions/http-curl/sitetosite/HTTPProtocol.cpp:107–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107int HttpSiteToSiteClient::readResponse(const std::shared_ptr<Transaction> &transaction, RespondCode &code, std::string &message) {
108 if (current_code == FINISH_TRANSACTION) {
109
110 if (transaction->getDirection() == SEND) {
111 auto stream = dynamic_cast<io::HttpStream*>(peer_->getStream());
112 stream->close();
113 auto client = stream->getClient();
114 if (client->getResponseCode() == 202) {
115 code = CONFIRM_TRANSACTION;
116 message = std::string(client->getResponseBody().data(), client->getResponseBody().size());
117 } else {
118 logger_->log_debug("Received response code %d", client->getResponseCode());
119 code = UNRECOGNIZED_RESPONSE_CODE;
120 }
121 return 1;
122 } else {
123 return 1;
124 }
125 } else if (transaction->getDirection() == RECEIVE) {
126 if (transaction->getState() == TRANSACTION_STARTED || transaction->getState() == DATA_EXCHANGED) {
127
128 if (current_code == CONFIRM_TRANSACTION && transaction->getState() == DATA_EXCHANGED) {
129 auto stream = dynamic_cast<io::HttpStream*>(peer_->getStream());
130 if (!stream->isFinished()) {
131 logger_->log_debug("confirm read for %s, but not finished ", transaction->getUUIDStr());
132 if (stream->waitForDataAvailable()) {
133 code = CONTINUE_TRANSACTION;
134 return 1;
135 }
136 }
137
138 code = CONFIRM_TRANSACTION;
139 } else {
140 auto stream = dynamic_cast<io::HttpStream*>(peer_->getStream());
141 if (stream->isFinished()) {
142 logger_->log_debug("Finished %s ", transaction->getUUIDStr());
143 code = FINISH_TRANSACTION;
144 current_code = FINISH_TRANSACTION;
145 } else {
146 if (stream->waitForDataAvailable()) {
147 logger_->log_debug("data is available, so continuing transaction %s ", transaction->getUUIDStr());
148 code = CONTINUE_TRANSACTION;
149 } else {
150 logger_->log_debug("No data available for transaction %s ", transaction->getUUIDStr());
151 code = FINISH_TRANSACTION;
152 current_code = FINISH_TRANSACTION;
153 }
154 }
155 }
156 } else if (transaction->getState() == TRANSACTION_CONFIRMED) {
157 closeTransaction(transaction->getUUID());
158 code = CONFIRM_TRANSACTION;
159 }
160
161 return 1;
162 } else if (transaction->getState() == TRANSACTION_CONFIRMED) {
163 closeTransaction(transaction->getUUID());
164 code = TRANSACTION_FINISHED;

Callers

nothing calls this directly

Calls 12

readResponseFunction · 0.85
getDirectionMethod · 0.80
getStreamMethod · 0.80
getResponseCodeMethod · 0.80
log_debugMethod · 0.80
waitForDataAvailableMethod · 0.80
closeMethod · 0.45
sizeMethod · 0.45
getStateMethod · 0.45
isFinishedMethod · 0.45
getUUIDStrMethod · 0.45
getUUIDMethod · 0.45

Tested by

no test coverage detected