Skip to content

Commit

Permalink
WebSkeletonApp needs changes to work
Browse files Browse the repository at this point in the history
* HttpParams needs virtual destructor
* HttpServerConnection doesn't deal with body - call request.setBody()
  • Loading branch information
mikee47 committed Oct 22, 2018
1 parent e8edfbd commit d998e9a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Sming/SmingCore/Network/Http/HttpParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
class HttpParams : public HashMap<String, String>, public Printable
{
public:
virtual ~HttpParams()
{
}

// Printable
virtual size_t printTo(Print& p) const;
};
Expand Down
13 changes: 11 additions & 2 deletions Sming/SmingCore/Network/Http/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ String HttpRequest::getQueryParameter(const String& parameterName, const String&

String HttpRequest::getBody()
{
if(bodyStream == nullptr || bodyStream->getStreamType() != eSST_Memory) {
if(bodyStream == nullptr) {
debug_w("bodyStream is null");
return nullptr;
}

if(bodyStream->getStreamType() != eSST_Memory) {
debug_w("bodyStream is wrong type (%d)", bodyStream->getStreamType());
return nullptr;
}

int len = bodyStream->available();
if(len <= 0) {
debug_w("bodyStream len <= 0");
// Cannot determine body size so need to use stream
return nullptr;
}

debug_w("bodyStream len = %d", len);

String ret;
if(ret.setLength(len)) {
len = bodyStream->readMemoryBlock(ret.begin(), len);
Expand Down Expand Up @@ -113,7 +122,7 @@ HttpRequest* HttpRequest::setResponseStream(ReadWriteStream* stream)
return this;
}

HttpRequest* HttpRequest::setBody(uint8_t* rawData, size_t length)
HttpRequest* HttpRequest::setBody(const uint8_t* rawData, size_t length)
{
auto memory = new MemoryDataStream();
auto written = memory->write(rawData, length);
Expand Down
2 changes: 1 addition & 1 deletion Sming/SmingCore/Network/Http/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class HttpRequest

HttpRequest* setBody(ReadWriteStream* stream);

HttpRequest* setBody(uint8_t* rawData, size_t length);
HttpRequest* setBody(const uint8_t* rawData, size_t length);

/**
* @brief Instead of storing the response body we can set a stream that will take care to process it
Expand Down
2 changes: 2 additions & 0 deletions Sming/SmingCore/Network/Http/HttpServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ int HttpServerConnection::staticOnBody(http_parser* parser, const char* at, size
}

// TODO: ...
connection->request.setBody((const uint8_t*)&at, length);

// if(connection->response.inputStream != nullptr) {
// int res = connection->response.inputStream->write((const uint8_t *)&at, length);
// if (res != length) {
Expand Down
5 changes: 3 additions & 2 deletions samples/Basic_WebSkeletonApp/app/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ void onConfiguration(HttpRequest& request, HttpResponse& response)
if(request.method == HTTP_POST) {
debugf("Update config");
// Update config
if(request.getBody() == NULL) {
String body = request.getBody();
if(body == nullptr) {
debugf("NULL bodyBuf");
return;
} else {
StaticJsonBuffer<ConfigJsonBufferSize> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(request.getBody());
JsonObject& root = jsonBuffer.parseObject(body);
root.prettyPrintTo(Serial); //Uncomment it for debuging

if(root["StaSSID"].success()) // Settings
Expand Down

0 comments on commit d998e9a

Please sign in to comment.