llhttp icon indicating copy to clipboard operation
llhttp copied to clipboard

How to interrupt llhttp_execute() in events like 'on_url_complete' ?

Open ldcsaa opened this issue 4 years ago • 4 comments

I try to interrupt llhttp_execute() by return -1 in events like on_url_complete, on_status_complete, on_header_field_complete, etc. But not work. Would you tell me how to interrupt llhttp_execute() in such events ?

ldcsaa avatar Apr 06 '21 12:04 ldcsaa

There is an HPE_PAUSED error that you can return from some of the callbacks. on_url_complete is not one of them, but there are others that should help you. Let me know what you think!

indutny avatar Apr 06 '21 15:04 indutny

For example, if receive an illegal request path like GET /a/b/非法/路径 I want to interrupt parsing an return error immediately.

ldcsaa avatar Apr 07 '21 13:04 ldcsaa

@ldcsaa perhaps you just want to build llhttp in strict mode? I believe it will do these checks for you. This can be done by compiling it with -DLLHTTP_STRICT_MODE=1.

indutny avatar Apr 07 '21 22:04 indutny

@indutny

  1. I had defined LLHTTP_STRICT_MODE 1, but now work.
  2. Another example - A: on_url_complete receive a legeal request path, but the path does not exists, then I want to interrupt parsing and return error immediately.
  3. Another example - B: on_header_field_complete / on_header_value_complete parses a field or value that application layer unexpected, then I want to interrupt parsing and return error immediately.

ldcsaa avatar Apr 12 '21 01:04 ldcsaa

I'll try to implement this. Will send a PR soon.

ShogunPanda avatar Aug 22 '22 13:08 ShogunPanda