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) { int Http1Session::on_read(const uint8_t *data, size_t len) {
auto htperr = auto htperr =
llhttp_execute(&htp_, reinterpret_cast<const char *>(data), len); llhttp_execute(&htp_, reinterpret_cast<const char *>(data), len);
auto nread = static_cast<size_t>( auto nread = htperr == HPE_OK
reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) - data); ? len
: static_cast<size_t>(reinterpret_cast<const uint8_t *>(
llhttp_get_error_pos(&htp_)) -
data);
if (client_->worker->config->verbose) { if (client_->worker->config->verbose) {
std::cout.write(reinterpret_cast<const char *>(data), nread); std::cout.write(reinterpret_cast<const char *>(data), nread);

View File

@ -1035,9 +1035,11 @@ int HttpClient::on_upgrade_read(const uint8_t *data, size_t len) {
auto htperr = auto htperr =
llhttp_execute(htp.get(), reinterpret_cast<const char *>(data), len); llhttp_execute(htp.get(), reinterpret_cast<const char *>(data), len);
auto nread = static_cast<size_t>( auto nread = htperr == HPE_OK
reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(htp.get())) - ? len
data); : static_cast<size_t>(reinterpret_cast<const uint8_t *>(
llhttp_get_error_pos(htp.get())) -
data);
if (config.verbose) { if (config.verbose) {
std::cout.write(reinterpret_cast<const char *>(data), nread); std::cout.write(reinterpret_cast<const char *>(data), nread);

View File

@ -1402,9 +1402,12 @@ int HttpDownstreamConnection::process_input(const uint8_t *data,
auto htperr = llhttp_execute(&response_htp_, auto htperr = llhttp_execute(&response_htp_,
reinterpret_cast<const char *>(data), datalen); reinterpret_cast<const char *>(data), datalen);
auto nproc = static_cast<size_t>( auto nproc =
reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&response_htp_)) - htperr == HPE_OK
data); ? datalen
: static_cast<size_t>(reinterpret_cast<const uint8_t *>(
llhttp_get_error_pos(&response_htp_)) -
data);
if (htperr != HPE_OK && if (htperr != HPE_OK &&
(!downstream_->get_upgraded() || htperr != HPE_PAUSED_UPGRADE)) { (!downstream_->get_upgraded() || htperr != HPE_PAUSED_UPGRADE)) {

View File

@ -629,8 +629,11 @@ int HttpsUpstream::on_read() {
auto htperr = llhttp_execute(&htp_, reinterpret_cast<const char *>(rb->pos()), auto htperr = llhttp_execute(&htp_, reinterpret_cast<const char *>(rb->pos()),
rb->rleft()); rb->rleft());
auto nread = reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) - auto nread =
rb->pos(); htperr == HPE_OK
? rb->rleft()
: reinterpret_cast<const uint8_t *>(llhttp_get_error_pos(&htp_)) -
rb->pos();
rb->drain(nread); rb->drain(nread);
rlimit->startw(); rlimit->startw();