PsychicHTTP v2 fixes
This commit is contained in:
@@ -5,11 +5,9 @@
|
||||
#include "PsychicStaticFileHandler.h"
|
||||
#include "PsychicWebHandler.h"
|
||||
#include "PsychicWebSocket.h"
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
#include "WiFi.h"
|
||||
#ifdef PSY_ENABLE_ETHERNET
|
||||
#include "ETH.h"
|
||||
#endif
|
||||
|
||||
PsychicHttpServer::PsychicHttpServer(uint16_t port)
|
||||
{
|
||||
maxRequestBodySize = MAX_REQUEST_BODY_SIZE;
|
||||
@@ -82,32 +80,11 @@ uint16_t PsychicHttpServer::getPort()
|
||||
return this->config.server_port;
|
||||
}
|
||||
|
||||
bool PsychicHttpServer::isConnected()
|
||||
{
|
||||
if (WiFi.softAPIP())
|
||||
return true;
|
||||
if (WiFi.localIP())
|
||||
return true;
|
||||
|
||||
#ifdef PSY_ENABLE_ETHERNET
|
||||
if (ETH.localIP())
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t PsychicHttpServer::start()
|
||||
{
|
||||
if (_running)
|
||||
return ESP_OK;
|
||||
|
||||
// starting without network will crash us.
|
||||
if (!isConnected()) {
|
||||
ESP_LOGE(PH_TAG, "Server start failed - no network.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t ret;
|
||||
|
||||
#ifdef ENABLE_ASYNC
|
||||
@@ -630,12 +607,20 @@ const std::list<PsychicClient*>& PsychicHttpServer::getClientList()
|
||||
|
||||
bool ON_STA_FILTER(PsychicRequest* request)
|
||||
{
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32H2)
|
||||
return false;
|
||||
#else
|
||||
return WiFi.localIP() == request->client()->localIP();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ON_AP_FILTER(PsychicRequest* request)
|
||||
{
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32H2)
|
||||
return false;
|
||||
#else
|
||||
return WiFi.softAPIP() == request->client()->localIP();
|
||||
#endif
|
||||
}
|
||||
|
||||
String urlDecode(const char* encoded)
|
||||
|
||||
@@ -73,7 +73,6 @@ class PsychicHttpServer
|
||||
virtual void setPort(uint16_t port);
|
||||
virtual uint16_t getPort();
|
||||
|
||||
bool isConnected();
|
||||
bool isRunning() { return _running; }
|
||||
esp_err_t begin() { return start(); }
|
||||
esp_err_t end() { return stop(); }
|
||||
|
||||
@@ -371,6 +371,11 @@ void PsychicRequest::_setUri(const char* uri)
|
||||
}
|
||||
}
|
||||
|
||||
int PsychicRequest::params()
|
||||
{
|
||||
return _params.size();
|
||||
}
|
||||
|
||||
void PsychicRequest::_addParams(const String& params, bool post)
|
||||
{
|
||||
size_t start = 0;
|
||||
@@ -422,6 +427,18 @@ PsychicWebParameter* PsychicRequest::getParam(const char* key)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PsychicWebParameter * PsychicRequest::getParam(int index)
|
||||
{
|
||||
if (_params.size() > index){
|
||||
std::list<PsychicWebParameter*>::iterator it = _params.begin();
|
||||
for(int i=0; i<index; i++){
|
||||
++it;
|
||||
}
|
||||
return *it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PsychicWebParameter* PsychicRequest::getParam(const char* key, bool isPost, bool isFile)
|
||||
{
|
||||
for (auto* param : _params)
|
||||
@@ -519,13 +536,14 @@ bool PsychicRequest::authenticate(const char* username, const char* password)
|
||||
// ESP_LOGD(PH_TAG, "Hash of user:realm:pass=%s", _H1.c_str());
|
||||
|
||||
String _H2 = "";
|
||||
if (_method == HTTP_GET) {
|
||||
http_method method = this->method();
|
||||
if (method == HTTP_GET) {
|
||||
_H2 = md5str(String(F("GET:")) + _url);
|
||||
} else if (_method == HTTP_POST) {
|
||||
} else if (method == HTTP_POST) {
|
||||
_H2 = md5str(String(F("POST:")) + _url);
|
||||
} else if (_method == HTTP_PUT) {
|
||||
} else if (method == HTTP_PUT) {
|
||||
_H2 = md5str(String(F("PUT:")) + _url);
|
||||
} else if (_method == HTTP_DELETE) {
|
||||
} else if (method == HTTP_DELETE) {
|
||||
_H2 = md5str(String(F("DELETE:")) + _url);
|
||||
} else {
|
||||
_H2 = md5str(String(F("GET:")) + _url);
|
||||
|
||||
@@ -130,9 +130,11 @@ class PsychicRequest
|
||||
void loadParams();
|
||||
PsychicWebParameter* addParam(PsychicWebParameter* param);
|
||||
PsychicWebParameter* addParam(const String& name, const String& value, bool decode = true, bool post = false);
|
||||
int params();
|
||||
bool hasParam(const char* key);
|
||||
bool hasParam(const char* key, bool isPost, bool isFile = false);
|
||||
PsychicWebParameter* getParam(const char* name);
|
||||
PsychicWebParameter* getParam(int index);
|
||||
PsychicWebParameter* getParam(const char* name, bool isPost, bool isFile = false);
|
||||
|
||||
const String getFilename();
|
||||
|
||||
@@ -6,8 +6,8 @@ PsychicStreamResponse::PsychicStreamResponse(PsychicResponse* response, const St
|
||||
: PsychicResponseDelegate(response), _buffer(NULL)
|
||||
{
|
||||
|
||||
setContentType(contentType.c_str());
|
||||
addHeader("Content-Disposition", "inline");
|
||||
//setContentType(contentType.c_str());
|
||||
//addHeader("Content-Disposition", "inline");
|
||||
}
|
||||
|
||||
PsychicStreamResponse::PsychicStreamResponse(PsychicResponse* response, const String& contentType, const String& name)
|
||||
|
||||
Reference in New Issue
Block a user