| 458 | } |
| 459 | |
| 460 | ssize_t HttpMessage::ParseFromArray(const char *data, const size_t length) { |
| 461 | if (Completed()) { |
| 462 | if (length == 0) { |
| 463 | return 0; |
| 464 | } |
| 465 | LOG(ERROR) << "Append data(len=" << length |
| 466 | << ") to already-completed message"; |
| 467 | return -1; |
| 468 | } |
| 469 | const size_t nprocessed = |
| 470 | http_parser_execute(&_parser, &g_parser_settings, data, length); |
| 471 | if (_parser.http_errno != 0) { |
| 472 | // May try HTTP on other formats, failure is norm. |
| 473 | RPC_VLOG << "Fail to parse http message, parser=" << _parser |
| 474 | << ", buf=`" << butil::StringPiece(data, length) << '\''; |
| 475 | return -1; |
| 476 | } |
| 477 | _parsed_length += nprocessed; |
| 478 | return nprocessed; |
| 479 | } |
| 480 | |
| 481 | ssize_t HttpMessage::ParseFromIOBuf(const butil::IOBuf &buf) { |
| 482 | if (Completed()) { |