Fix llhttp_get_error_pos usage

It returns NULL if return value is HPE_OK.
This commit is contained in:
Tatsuhiro Tsujikawa 2019-04-21 00:07:11 +09:00
parent a3a034813b
commit 0288093caf
4 changed files with 21 additions and 10 deletions

View File

@ -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);

View File

@ -1035,8 +1035,10 @@ 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())) -
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) {

View File

@ -1402,8 +1402,11 @@ 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_)) -
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 &&

View File

@ -629,7 +629,10 @@ 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_)) -
auto nread =
htperr == HPE_OK
? rb->rleft()
: reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) -
rb->pos();
rb->drain(nread);
rlimit->startw();