|
30 | 30 | #include "v8.h"
|
31 | 31 |
|
32 | 32 | #include <stdlib.h> // free()
|
33 |
| -#include <string.h> // strdup() |
| 33 | +#include <string.h> // strdup(), strchr() |
34 | 34 |
|
35 | 35 | #include "http_parser_adaptor.h"
|
36 | 36 |
|
@@ -367,7 +367,7 @@ class Parser : public AsyncWrap, public StreamListener {
|
367 | 367 | if (r.IsEmpty()) {
|
368 | 368 | got_exception_ = true;
|
369 | 369 | #ifdef NODE_EXPERIMENTAL_HTTP
|
370 |
| - llhttp_set_error_reason(&parser_, "JS Exception"); |
| 370 | + llhttp_set_error_reason(&parser_, "HPE_JS_EXCEPTION:JS Exception"); |
371 | 371 | #endif /* NODE_EXPERIMENTAL_HTTP */
|
372 | 372 | return HPE_USER;
|
373 | 373 | }
|
@@ -395,7 +395,7 @@ class Parser : public AsyncWrap, public StreamListener {
|
395 | 395 |
|
396 | 396 | if (r.IsEmpty()) {
|
397 | 397 | got_exception_ = true;
|
398 |
| - return HPE_USER; |
| 398 | + return -1; |
399 | 399 | }
|
400 | 400 |
|
401 | 401 | return 0;
|
@@ -712,13 +712,23 @@ class Parser : public AsyncWrap, public StreamListener {
|
712 | 712 | env()->bytes_parsed_string(),
|
713 | 713 | nread_obj).FromJust();
|
714 | 714 | #ifdef NODE_EXPERIMENTAL_HTTP
|
715 |
| - obj->Set(env()->context(), |
716 |
| - env()->code_string(), |
717 |
| - OneByteString(env()->isolate(), |
718 |
| - llhttp_errno_name(err))).FromJust(); |
719 |
| - obj->Set(env()->context(), |
720 |
| - env()->reason_string(), |
721 |
| - OneByteString(env()->isolate(), parser_.reason)).FromJust(); |
| 715 | + const char* errno_reason = llhttp_get_error_reason(&parser_); |
| 716 | + |
| 717 | + Local<String> code; |
| 718 | + Local<String> reason; |
| 719 | + if (err == HPE_USER) { |
| 720 | + const char* colon = strchr(errno_reason, ':'); |
| 721 | + CHECK_NE(colon, nullptr); |
| 722 | + code = OneByteString(env()->isolate(), errno_reason, |
| 723 | + colon - errno_reason); |
| 724 | + reason = OneByteString(env()->isolate(), colon + 1); |
| 725 | + } else { |
| 726 | + code = OneByteString(env()->isolate(), llhttp_errno_name(err)); |
| 727 | + reason = OneByteString(env()->isolate(), errno_reason); |
| 728 | + } |
| 729 | + |
| 730 | + obj->Set(env()->context(), env()->code_string(), code).FromJust(); |
| 731 | + obj->Set(env()->context(), env()->reason_string(), reason).FromJust(); |
722 | 732 | #else /* !NODE_EXPERIMENTAL_HTTP */
|
723 | 733 | obj->Set(env()->context(),
|
724 | 734 | env()->code_string(),
|
@@ -790,7 +800,7 @@ class Parser : public AsyncWrap, public StreamListener {
|
790 | 800 | #ifdef NODE_EXPERIMENTAL_HTTP
|
791 | 801 | header_nread_ += len;
|
792 | 802 | if (header_nread_ >= kMaxHeaderSize) {
|
793 |
| - llhttp_set_error_reason(&parser_, "Headers overflow"); |
| 803 | + llhttp_set_error_reason(&parser_, "HPE_HEADER_OVERFLOW:Header overflow"); |
794 | 804 | return HPE_USER;
|
795 | 805 | }
|
796 | 806 | #endif /* NODE_EXPERIMENTAL_HTTP */
|
|
0 commit comments