Skip to content

Commit 288fc29

Browse files
committed
Add options to disable flash usage and basic authentication
1 parent 216309e commit 288fc29

File tree

11 files changed

+43
-44
lines changed

11 files changed

+43
-44
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ Documentation
4545

4646
Documentation available in the [ArduinoHttpServer Github wiki](https://github.com/QuickSander/ArduinoHttpServer/wiki)
4747

48+
### Compiler options
49+
The library can be adjusted to include less or more features depending on the board you use and your desires for hardware usage. Specify these in your project's ```platformio.ini``` via the [```build_flags```](https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-flags) argument or as ```#define``` in your source/header code before including ```ArduinoHttpServer.h```.
50+
51+
| ```#define``` | Description |
52+
| ------------- | ----------- |
53+
| ```ARDUINO_HTTP_SERVER_DEBUG``` | Enable debug logging printed towards the default Serial port |
54+
| ```ARDUINO_HTTP_SERVER_NO_FLASH``` | Do not put string literals used inside the library's implementation in flash memory. Increases RAM usage, decreases flash usage. |
55+
| ```ARDUINO_HTTP_SERVER_NO_BASIC_AUTH``` | Disable HTTP basic authentication support. Removes the need for the Base64 library. |
56+
4857
Characteristics
4958
---------------
5059
* HTTP parser with protocol validation.

examples/HelloHttp/HelloHttp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void loop()
5757
// Optionally athenticate incoming request
5858
if(!httpRequest.authenticate("user", "secret"))
5959
{
60+
// Client did not supply correct credentials. Send request to authenticate itself via autheticate reply.
6061
ArduinoHttpServer::StreamHttpAuthenticateReply httpReply(client, httpRequest.getContentType());
6162
httpReply.send();
6263
}

lib/readme.txt

Lines changed: 0 additions & 36 deletions
This file was deleted.

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "http://sander.technology",
99
"maintainer": true
1010
},
11-
"version": "0.10.0",
11+
"version": "0.10.1",
1212
"repository":
1313
{
1414
"type": "git",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoHttpServer
2-
version=0.10.0
2+
version=0.10.1
33
author=Sander van Woensel <sander@vanwoensel.me>
44
maintainer=Sander van Woensel <sander@vanwoensel.me>
55
sentence=Server side minimalistic HTTP protocol implementation.

platformio.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
src_dir = examples/HelloHttp
1313
lib_dir = ../
1414

15+
1516
[env:esp01]
1617
platform = espressif8266
1718
framework = arduino
1819
board = esp01
19-
lib_deps = agdl/Base64@^1.0.0
20+
#lib_deps = agdl/Base64@^1.0.0
21+
build_flags =
22+
;-DARDUINO_HTTP_SERVER_DEBUG
23+
;-DARDUINO_HTTP_SERVER_NO_FLASH
24+
;-DARDUINO_HTTP_SERVER_NO_BASIC_AUTH
2025

2126
[env:uno]
2227
platform = atmelavr

src/internals/ArduinoHttpServerDebug.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88
//! Debug support
99

10-
//#define ARDUINO_HTTP_SERVER_DEBUG
1110
#ifdef ARDUINO_HTTP_SERVER_DEBUG
1211
#define DEBUG_ARDUINO_HTTP_SERVER_PRINT(...) Serial.print(__VA_ARGS__)
1312
#define DEBUG_ARDUINO_HTTP_SERVER_PRINTLN(...) Serial.println(__VA_ARGS__)
@@ -17,7 +16,6 @@
1716
#endif
1817

1918

20-
//#define ARDUINO_HTTP_SERVER_NO_FLASH
2119
#ifdef ARDUINO_HTTP_SERVER_NO_FLASH
2220
#define AHS_F(x) (x)
2321
#else

src/internals/FixString.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class FixString
3030

3131
// Constructors
3232
explicit FixString(const char* pCStr="", size_t len=NPOS);
33+
#ifndef ARDUINO_HTTP_SERVER_NO_FLASH
3334
explicit FixString(const __FlashStringHelper * pFlashStr);
35+
#endif
3436
explicit FixString(const String& arduinoStr);
3537
template<size_t RHS_SIZE> FixString(const FixString<RHS_SIZE>& fixStr); // Not explicit to allow for normal conversions where only size differs.
3638
FixString(const FixString<MAX_SIZE>& fixStr) = default; // Not marked as "explicit" to allow normal return statements
@@ -40,7 +42,9 @@ class FixString
4042

4143
// Assignment
4244
FixString<MAX_SIZE>& operator=(const char* pCStr);
45+
#ifndef ARDUINO_HTTP_SERVER_NO_FLASH
4346
FixString<MAX_SIZE>& operator=(const __FlashStringHelper * str);
47+
#endif
4448
FixString<MAX_SIZE>& operator=(const String& arduinostr);
4549
template<size_t RHS_SIZE> FixString<MAX_SIZE>& operator=(const FixString<RHS_SIZE>& fixStr);
4650
// We need this since move constructor implicitely declares assignment operators private.
@@ -60,7 +64,9 @@ class FixString
6064

6165
// Modification
6266
FixString<MAX_SIZE>& operator+=(const char *pRhs);
67+
#ifndef ARDUINO_HTTP_SERVER_NO_FLASH
6368
FixString<MAX_SIZE>& operator+=(const __FlashStringHelper *pRhs);
69+
#endif
6470
template<size_t RHS_SIZE> FixString<MAX_SIZE>& operator+=(const FixString<RHS_SIZE>& rhs);
6571

6672

@@ -115,13 +121,14 @@ ArduinoHttpServer::FixString<MAX_SIZE>::FixString(const char* pCStr, size_t len)
115121

116122
//------------------------------------------------------------------------------
117123
//! \brief Construct using Flash String pointer.
124+
#ifndef ARDUINO_HTTP_SERVER_NO_FLASH
118125
template <size_t MAX_SIZE>
119126
ArduinoHttpServer::FixString<MAX_SIZE>::FixString(const __FlashStringHelper * pFlashStr) :
120127
m_buffer{0}
121128
{
122129
strcpy_P(m_buffer, reinterpret_cast<PGM_P>(pFlashStr));
123130
}
124-
131+
#endif
125132

126133
//------------------------------------------------------------------------------
127134
//! \brief Construct using an Arduino String object.
@@ -156,11 +163,13 @@ ArduinoHttpServer::FixString<MAX_SIZE>& ArduinoHttpServer::FixString<MAX_SIZE>::
156163

157164
//------------------------------------------------------------------------------
158165
//! \brief Assignment operator for Flash based strings.
166+
#ifndef ARDUINO_HTTP_SERVER_NO_FLASH
159167
template <size_t MAX_SIZE>
160168
ArduinoHttpServer::FixString<MAX_SIZE>& ArduinoHttpServer::FixString<MAX_SIZE>::operator=(const __FlashStringHelper * pFlashStr)
161169
{
162170
return (*this = FixString<MAX_SIZE>(pFlashStr));
163171
}
172+
#endif
164173

165174
//------------------------------------------------------------------------------
166175
//! \brief Assignment operator for Arduino Strings.
@@ -291,12 +300,14 @@ ArduinoHttpServer::FixString<MAX_SIZE>& ArduinoHttpServer::FixString<MAX_SIZE>::
291300

292301
//------------------------------------------------------------------------------
293302
//! \brief Concatenate with Flash String.
303+
#ifndef ARDUINO_HTTP_SERVER_NO_FLASH
294304
template <size_t MAX_SIZE>
295305
ArduinoHttpServer::FixString<MAX_SIZE>& ArduinoHttpServer::FixString<MAX_SIZE>::operator+=(const __FlashStringHelper *pRhs)
296306
{
297307
strncpy_P(m_buffer+length(), (PGM_P)pRhs, MAX_SIZE - length() - 1);
298308
return *this;
299309
}
310+
#endif
300311

301312
//------------------------------------------------------------------------------
302313
//! \brief Concatenate FixString.

src/internals/StreamHttpReply.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ String ArduinoHttpServer::StreamHttpErrorReply::getJsonBody(const String& data)
134134
// Class Definition
135135
//------------------------------------------------------------------------------
136136

137+
#ifndef ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
138+
137139
ArduinoHttpServer::StreamHttpAuthenticateReply::StreamHttpAuthenticateReply(Stream& stream, const String& contentType) :
138140
AbstractStreamHttpReply(stream, contentType, "401")
139141
{
@@ -155,3 +157,5 @@ void ArduinoHttpServer::StreamHttpAuthenticateReply::send()
155157
getStream().println(AHS_F(""));
156158
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN("done.");
157159
}
160+
161+
#endif

src/internals/StreamHttpReply.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ class StreamHttpErrorReply: public AbstractStreamHttpReply
6363
// Class Declaration
6464
//------------------------------------------------------------------------------
6565
//! Authenticate reply
66+
#ifndef ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
6667
class StreamHttpAuthenticateReply: public AbstractStreamHttpReply
6768
{
6869
public:
6970
StreamHttpAuthenticateReply(Stream& stream, const String& contentType);
7071
virtual void send();
7172
};
72-
73+
#endif
7374

7475
//------------------------------------------------------------------------------
7576
// Class Declaration

src/internals/StreamHttpRequest.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include "ArduinoHttpServerDebug.h"
1818

1919
#include <Arduino.h>
20-
#include <Base64.h>
20+
#ifndef ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
21+
#include <Base64.h>
22+
#endif
2123

2224
#include <string.h>
2325

@@ -66,7 +68,9 @@ class StreamHttpRequest
6668
Stream& getStream() { return m_stream; };
6769

6870
// Validate if client provided credentials match _username_ and _password_.
71+
#ifndef ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
6972
bool authenticate(const char * username, const char * password) const;
73+
#endif
7074

7175
private:
7276

@@ -379,6 +383,7 @@ const ArduinoHttpServer::ErrorString ArduinoHttpServer::StreamHttpRequest<MAX_BO
379383
return errorString;
380384
}
381385

386+
#ifndef ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
382387
template <size_t MAX_BODY_SIZE>
383388
bool ArduinoHttpServer::StreamHttpRequest<MAX_BODY_SIZE>::authenticate(const char *username, const char *password) const
384389
{
@@ -415,5 +420,6 @@ bool ArduinoHttpServer::StreamHttpRequest<MAX_BODY_SIZE>::authenticate(const cha
415420

416421
return false;
417422
}
423+
#endif
418424

419425
#endif // __ArduinoHttpServer__StreamHttpRequest__

0 commit comments

Comments
 (0)