Open adadgio opened 7 years ago
Hi, it is indeed - thanks for reporting! Working on it :)
@marcoschwartz Thanks for sharing this project.
No offense. I read through void process(char c)
code. It is far from ideal to process HTTP request.
That part of code is buggy. If you decide to ignore HTTP post/get/put/delete method and ignore any content type, just focus on parsing HTTP header. There should be a better way to get this thing right.
If you can't get this parsing right, there is no extension at all. That's the whole purpose of people using it as REST server.
After skimming through RFC 2616, I proposed that it only scans the request line to get Method
and REQUEST-URI
.
Page 34
5.1 Request-Line
The Request-Line begins with a method token, followed by the
Request-URI and the protocol version, and ending with CRLF. The
elements are separated by SP characters. No CR or LF is allowed
except in the final CRLF sequence.
Request-Line = Method SP Request-URI SP HTTP-Version CRLF
For simplicity and consistency, I propose the following changes:
I'm going to override aREST and provide a sample user-defined classes.
class bREST: public aREST {
/**
* @brief process parse one and only one Request-Line (Method SP Request-URI SP HTTP-Version CRLF)
* @param c one character from
*/
void process(char c) override {
}
/**
* @brief send_command executes command based on method and request URI from HTTP request
* @param headers
* @param decodeArgs
* @return
*/
bool send_command(bool headers, bool decodeArgs) override {
}
}
I decided to create a fork https://github.com/rickyzhang82/bREST.
@rickyzhang82 Thanks for your work! And sorry all for the time to get back on this, I know it is a very important fix for aREST.
@rickyzhang82 Could you actually create a pull request with the changes from your fork? I'd be more than happy to test it and to merge it back into aREST to solve the bug.
@marcoschwartz
If you have read my proposal, my design and implementation will not honor the way you expose RESTful API. I'd recommend you spending some time to read the doc in my fork and see if the changes is desirable.
Regarding to testing, I already did several tests on ESP8266 and Arduino UNO.
One of them is the sample code in my fork.
Another test is to connect ESP8266 to Arduino UNO which controls pan and tilt servo by RESTful API. Both ESP8266 and Arduino UNO run bREST. While the ESP8266 in TCP/IP relays request to UNO through serial port, Arduino UNO responds in the same bREST and get back to TCP/IP. I'd believe that's what the most Arduino would want given the fact that there is limited number of pin in ESP8266.
I don't know if this issue is serious or not, but i suspect it might cause problems.
When i create a function endpoint such as
/test
, the server will respond to all other URLs matchingtest
such as/testanythingelse
...Also, any function is ran twice ... (separate issue?)