|
10 | 10 | #include <cc/data.h>
|
11 | 11 | #include <http/client.h>
|
12 | 12 | #include <http/http_types.h>
|
| 13 | +#include <http/response_parser.h> |
13 | 14 |
|
14 | 15 | #include <boost/asio/read.hpp>
|
15 | 16 | #include <boost/asio/buffer.hpp>
|
|
18 | 19 |
|
19 | 20 | using namespace boost::asio::ip;
|
20 | 21 | using namespace isc::asiolink;
|
| 22 | +using namespace isc::http; |
21 | 23 |
|
22 | 24 | /// @brief Common base for test HTTP/HTTPS clients.
|
23 | 25 | class BaseTestHttpClient : public boost::noncopyable {
|
@@ -210,12 +212,29 @@ class TestHttpClient : public BaseTestHttpClient {
|
210 | 212 | buf_.data() + bytes_transferred);
|
211 | 213 | }
|
212 | 214 |
|
213 |
| - // Two consecutive new lines end headers, " } ]" sequence |
214 |
| - // end large response we're expecting. |
215 |
| - if ((response_.find("\r\n\r\n", 0) != std::string::npos) && |
216 |
| - ((response_.size() < 1000) || |
217 |
| - (response_.rfind(" } ]") == (response_.size() - 4)))) { |
218 |
| - receive_done_ = true; |
| 215 | + // Two consecutive new lines end the part of the response we're |
| 216 | + // expecting. |
| 217 | + bool need_data(true); |
| 218 | + if (response_.find("\r\n\r\n", 0) != std::string::npos) { |
| 219 | + // Try to parse the response. |
| 220 | + try { |
| 221 | + HttpResponse hr; |
| 222 | + HttpResponseParser parser(hr); |
| 223 | + parser.initModel(); |
| 224 | + parser.postBuffer(&response_[0], response_.size()); |
| 225 | + parser.poll(); |
| 226 | + if (!parser.needData()) { |
| 227 | + need_data = false; |
| 228 | + if (parser.httpParseOk()) { |
| 229 | + receive_done_ = true; |
| 230 | + } |
| 231 | + } |
| 232 | + } catch (const std::exception& ex) { |
| 233 | + need_data = false; |
| 234 | + ADD_FAILURE() << "error parsing response: " << ex.what(); |
| 235 | + } |
| 236 | + } |
| 237 | + if (!need_data) { |
219 | 238 | io_service_->stop();
|
220 | 239 | } else {
|
221 | 240 | receivePartialResponse();
|
@@ -474,12 +493,29 @@ class TestHttpsClient : public BaseTestHttpClient {
|
474 | 493 | buf_.data() + bytes_transferred);
|
475 | 494 | }
|
476 | 495 |
|
477 |
| - // Two consecutive new lines end headers, " } ]" sequence |
478 |
| - // end large response we're expecting. |
479 |
| - if ((response_.find("\r\n\r\n", 0) != std::string::npos) && |
480 |
| - ((response_.size() < 1000) || |
481 |
| - (response_.rfind(" } ]") == (response_.size() - 4)))) { |
482 |
| - receive_done_ = true; |
| 496 | + // Two consecutive new lines end the part of the response we're |
| 497 | + // expecting. |
| 498 | + bool need_data(true); |
| 499 | + if (response_.find("\r\n\r\n", 0) != std::string::npos) { |
| 500 | + // Try to parse the response. |
| 501 | + try { |
| 502 | + HttpResponse hr; |
| 503 | + HttpResponseParser parser(hr); |
| 504 | + parser.initModel(); |
| 505 | + parser.postBuffer(&response_[0], response_.size()); |
| 506 | + parser.poll(); |
| 507 | + if (!parser.needData()) { |
| 508 | + need_data = false; |
| 509 | + if (parser.httpParseOk()) { |
| 510 | + receive_done_ = true; |
| 511 | + } |
| 512 | + } |
| 513 | + } catch (const std::exception& ex) { |
| 514 | + need_data = false; |
| 515 | + ADD_FAILURE() << "error parsing response: " << ex.what(); |
| 516 | + } |
| 517 | + } |
| 518 | + if (!need_data) { |
483 | 519 | io_service_->stop();
|
484 | 520 | } else {
|
485 | 521 | receivePartialResponse();
|
|
0 commit comments