eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.62k stars 758 forks source link

Whitespace encoding in route regular expression #84

Open ydarma opened 7 years ago

ydarma commented 7 years ago

Hi,

first thank you for the Simple-Web-Server which is amazing.

If a path contains a whitespace, the \s pattern won't match. For instance :

^/search?q="two\s+words"$

We need to write instead :

^/search?q="two(?:(?:%20)|\s)+words"$

This is a bit annoying...

Thanks, Yves

ydarma commented 7 years ago

re-Hi,

Actually, we have the same problem with all special characters. For instance a [ must be tested as (?:%5B)|\[ ...

eidheim commented 7 years ago

Since parsing of a HTTP path variables is outside of the scope of this project, you would have to implement this yourself. You could use ^/search?(.*)$ as regex and parse the path_match[1] in the resource function.

Personally, I would not use the HTTP path to pass such variables though, since it is limited (essentially only an associate table of strings, strings (no object structure that is)), and use the content (body) in the request instead (and here be able to use a JSON structure for instance). Even though this might go against the HTTP recommendation for especially GET requests.