Commit 0288093c authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Fix llhttp_get_error_pos usage

It returns NULL if return value is HPE_OK.
parent a3a03481
......@@ -203,8 +203,11 @@ int Http1Session::submit_request() {
int Http1Session::on_read(const uint8_t *data, size_t len) {
auto htperr =
llhttp_execute(&htp_, reinterpret_cast<const char *>(data), len);
auto nread = static_cast<size_t>(
reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) - data);
auto nread = htperr == HPE_OK
? len
: static_cast<size_t>(reinterpret_cast<const uint8_t *>(
llhttp_get_error_pos(&htp_)) -
data);
if (client_->worker->config->verbose) {
std::cout.write(reinterpret_cast<const char *>(data), nread);
......
......@@ -1035,9 +1035,11 @@ int HttpClient::on_upgrade_read(const uint8_t *data, size_t len) {
auto htperr =
llhttp_execute(htp.get(), reinterpret_cast<const char *>(data), len);
auto nread = static_cast<size_t>(
reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(htp.get())) -
data);
auto nread = htperr == HPE_OK
? len
: static_cast<size_t>(reinterpret_cast<const uint8_t *>(
llhttp_get_error_pos(htp.get())) -
data);
if (config.verbose) {
std::cout.write(reinterpret_cast<const char *>(data), nread);
......
......@@ -1402,9 +1402,12 @@ int HttpDownstreamConnection::process_input(const uint8_t *data,
auto htperr = llhttp_execute(&response_htp_,
reinterpret_cast<const char *>(data), datalen);
auto nproc = static_cast<size_t>(
reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&response_htp_)) -
data);
auto nproc =
htperr == HPE_OK
? datalen
: static_cast<size_t>(reinterpret_cast<const uint8_t *>(
llhttp_get_error_pos(&response_htp_)) -
data);
if (htperr != HPE_OK &&
(!downstream_->get_upgraded() || htperr != HPE_PAUSED_UPGRADE)) {
......
......@@ -629,8 +629,11 @@ int HttpsUpstream::on_read() {
auto htperr = llhttp_execute(&htp_, reinterpret_cast<const char *>(rb->pos()),
rb->rleft());
auto nread = reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) -
rb->pos();
auto nread =
htperr == HPE_OK
? rb->rleft()
: reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) -
rb->pos();
rb->drain(nread);
rlimit->startw();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment