-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/add options method #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,10 @@ | |
| #define __ArduinoHttpServer__StreamHttpReply__ | ||
|
|
||
| #include <Arduino.h> | ||
|
|
||
| #include "ArduinoHttpServerDebug.h" | ||
|
|
||
| #define MAX_HEADERS 3 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change it to modern C++ typesafe constexpr?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can give it a shot, but I haven't used those ever (I am not a native C++ speaker). |
||
|
|
||
| namespace ArduinoHttpServer | ||
| { | ||
|
|
||
|
|
@@ -25,6 +26,7 @@ class AbstractStreamHttpReply | |
| { | ||
|
|
||
| public: | ||
| void addHeader(const String& name, const String &value); | ||
| virtual void send(const String& data, const String& title); | ||
|
|
||
| protected: | ||
|
|
@@ -37,7 +39,9 @@ class AbstractStreamHttpReply | |
| constexpr static const char* CONTENT_TYPE_APPLICATION_JSON PROGMEM = "application/json"; | ||
|
|
||
| private: | ||
|
|
||
| String m_headerNames[MAX_HEADERS]; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't mind, I think I will rewrite it to become an array of HttpField objects.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course I don't mind. Your C++ is probably better than mine :). |
||
| String m_headerValues[MAX_HEADERS]; | ||
| int m_headerCount = 0; | ||
| Stream& m_stream; | ||
| String m_contentType; //!< Needs to be overridden to default when required. Therefore not const. | ||
| const String m_code; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,7 +28,7 @@ namespace ArduinoHttpServer | |||||
|
|
||||||
| enum class Method : char | ||||||
| { | ||||||
| Invalid, Get, Put, Post, Head, Delete | ||||||
| Invalid, Get, Put, Post, Head, Delete, Options | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -240,8 +240,8 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_SIZE>::parseMethod(char lineB | |||||
| if(m_error!=Error::OK) { return; } | ||||||
|
|
||||||
| // First strtok call, initialize with cached line buffer. | ||||||
| // len("DELETE") + 1 for terminating null = 7 | ||||||
| FixString<7U> token(strtok_r(lineBuffer, " ", &m_lineBufferStrTokContext)); | ||||||
| // len("OPTIONS") + 1 for terminating null = 7 | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| FixString<8U> token(strtok_r(lineBuffer, " ", &m_lineBufferStrTokContext)); | ||||||
|
|
||||||
| if(token == "GET") | ||||||
| { | ||||||
|
|
@@ -263,6 +263,10 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_SIZE>::parseMethod(char lineB | |||||
| { | ||||||
| m_method = Method::Delete; | ||||||
| } | ||||||
| else if (token == "OPTIONS") | ||||||
| { | ||||||
| m_method = Method::Options; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| m_method = Method::Invalid; | ||||||
|
|
@@ -290,7 +294,6 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_SIZE>::parseVersion() | |||||
| else | ||||||
| { | ||||||
| setError(Error::PARSE_ERROR_INVALID_HTTP_VERSION, version); | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| } | ||||||
|
|
@@ -319,7 +322,7 @@ template <size_t MAX_BODY_SIZE> | |||||
| void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_SIZE>::parseField(char lineBuffer[]) | ||||||
| { | ||||||
| if(m_error!=Error::OK) { return; } | ||||||
|
|
||||||
| ArduinoHttpServer::HttpField httpField(lineBuffer); | ||||||
|
|
||||||
| if(httpField.getType() == ArduinoHttpServer::HttpField::Type::CONTENT_TYPE) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a struct with a name and value pair?