Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

match wrong callback when set two same path #129

Open
lwzcwh opened this issue Mar 7, 2019 · 4 comments
Open

match wrong callback when set two same path #129

lwzcwh opened this issue Mar 7, 2019 · 4 comments

Comments

@lwzcwh
Copy link

lwzcwh commented Mar 7, 2019

https://github.com/criticalstack/libevhtp/blob/0f52e868d88391d0f61d180c136404da3079efd9/evhtp.c#L906
when we set two path using evhtp_set_cb like below,it will math wrong cb:
path1: /abc/0 cb1
path2:/abc/012 cb2

when we call the rest server using path /abc/012 ,it will call cb1

@NathanFrench
Copy link
Collaborator

It also searches in an ordered manner; have you tried putting the longest match first?

@lwzcwh
Copy link
Author

lwzcwh commented Mar 8, 2019

It also searches in an ordered manner; have you tried putting the longest match first?
yeah,I tried, it works. but I'm a low-level component, and the real user is someone else, and I can't ask them to use it like this. I need to find a way to circumvent this problem, or our upper-level code needs to be changed.

@NathanFrench
Copy link
Collaborator

I see. Any auto-sort would only apply to static URI's, I cannot sort based on regex or globs for obvious reasons. Is that OK?

NathanFrench added a commit that referenced this issue Mar 13, 2019
Added a compile-time flag -DEVHTP_SORT_CALLBACKS which will auto-sort
globs and non-regex callbacks to search from longest to shortest.

This is optional since we do not want to potentially mess up any code
currently running in production that does this sort of thing manually
(ie ordering code).
@NathanFrench
Copy link
Collaborator

NathanFrench commented Mar 13, 2019

Hello @lwzcwh,

I pushed up a test branch for you here: https://github.com/criticalstack/libevhtp/tree/issue129 (diff here: https://github.com/criticalstack/libevhtp/compare/issue129)

I am leaving this as an optional compile-time flag, you must run cmake with the following:

cmake -DEVHTP_SORT_CALLBACKS=ON ..

..along with any other options you would like.

Since I do not want to affect any other code, this is not enabled by default. If this looks OK to you, I will merge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants