Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ESPWebThingAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@

class WebThingAdapter {
public:
WebThingAdapter(String _name, IPAddress _ip, uint16_t _port = 80)
: server(_port), name(_name), ip(_ip.toString()), port(_port) {}
WebThingAdapter(String _name, IPAddress _ip, uint16_t _port = 80,
bool _disableHostValidation = false)
: server(_port), name(_name), ip(_ip.toString()), port(_port),
disableHostValidation(_disableHostValidation) {}

void begin() {
name.toLowerCase();
Expand Down Expand Up @@ -197,12 +199,17 @@ class WebThingAdapter {
String name;
String ip;
uint16_t port;
bool disableHostValidation;
ThingDevice *firstDevice = nullptr;
ThingDevice *lastDevice = nullptr;
char body_data[ESP_MAX_PUT_BODY_SIZE];
bool b_has_body_data = false;

bool verifyHost(AsyncWebServerRequest *request) {
if (disableHostValidation) {
return true;
}

AsyncWebHeader *header = request->getHeader("Host");
if (header == nullptr) {
request->send(403);
Expand Down
11 changes: 9 additions & 2 deletions EthernetWebThingAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ enum ReadState {

class WebThingAdapter {
public:
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80)
: name(_name), port(_port), server(_port)
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80,
bool _disableHostValidation = false)
: name(_name), port(_port), server(_port),
disableHostValidation(_disableHostValidation)
#ifdef CONFIG_MDNS
,
mdns(udp)
Expand Down Expand Up @@ -240,6 +242,7 @@ class WebThingAdapter {
private:
String name, ip;
uint16_t port;
bool disableHostValidation;
EthernetServer server;
EthernetClient client;
#ifdef CONFIG_MDNS
Expand All @@ -260,6 +263,10 @@ class WebThingAdapter {
ThingDevice *firstDevice = nullptr, *lastDevice = nullptr;

bool verifyHost() {
if (disableHostValidation) {
return true;
}

int colonIndex = host.indexOf(':');
if (colonIndex >= 0) {
host.remove(colonIndex);
Expand Down
11 changes: 9 additions & 2 deletions WiFi101WebThingAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ enum ReadState {

class WebThingAdapter {
public:
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80)
: name(_name), port(_port), server(_port), mdns(udp) {
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80,
bool _disableHostValidation)
: name(_name), port(_port), server(_port),
disableHostValidation(_disableHostValidation), mdns(udp) {
ip = "";
for (int i = 0; i < 4; i++) {
ip += _ip & 0xff;
Expand Down Expand Up @@ -228,6 +230,7 @@ class WebThingAdapter {
private:
String name, ip;
uint16_t port;
bool disableHostValidation;
WiFiServer server;
WiFiClient client;
WiFiUDP udp;
Expand All @@ -246,6 +249,10 @@ class WebThingAdapter {
ThingDevice *firstDevice = nullptr, *lastDevice = nullptr;

bool verifyHost() {
if (disableHostValidation) {
return true;
}

int colonIndex = host.indexOf(':');
if (colonIndex >= 0) {
host.remove(colonIndex);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "webthing-arduino",
"description": "A library for creating Web Things using the Web of Things API. Runs on ESP8266, ESP32, Ethernet, and WiFi101-compatible boards. Compatible with the WebThings Gateway.",
"keywords": "Communication",
"version": "0.11.7",
"version": "0.12.0",
"authors": {
"name": "WebThingsIO",
"email": "team@webthings.io",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=webthing-arduino
version=0.11.7
version=0.12.0
author=WebThingsIO <team@webthings.io>
maintainer=WebThingsIO <team@webthings.io>
sentence=A library for creating Web Things using the Web of Things API
Expand Down