Skip to content

Commit

Permalink
Merge pull request #97 from lasselukkari/fix-read-return-value
Browse files Browse the repository at this point in the history
Fix read return value
  • Loading branch information
lasselukkari authored Jan 23, 2021
2 parents db94041 + 532fba2 commit db60f60
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=aWOT
version=3.2.0
version=3.2.1
author=Lasse Lukkari <lasse.lukkari@gmail.com>
maintainer=Lasse Lukkari <lasse.lukkari@gmail.com>
sentence=Arduino web server library.
Expand Down
1 change: 1 addition & 0 deletions src/aWOT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ int Request::read(uint8_t* buf, size_t size) {
while (m_pushbackDepth > 0) {
*buf++ = m_pushback[--m_pushbackDepth];
size--;
ret++;
}

int read = m_stream->read(buf, (size < m_left ? size : m_left));
Expand Down
33 changes: 33 additions & 0 deletions test/buffered-read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,46 @@ void handler(Request & req, Response & res) {
res.write(buffer, read);
}

void readCountHandler(Request & req, Response & res) {
uint8_t buffer[100] = {};
req.push(req.read());

int read = req.read(buffer , 100);

res.print(read);
}

unittest(buffered_read) {
const char *request =
"POST / HTTP/1.0" CRLF
"Content-Length: 4" CRLF
CRLF
"body";

const char *expected =
"HTTP/1.1 200 OK" CRLF
"Content-Type: text/plain" CRLF
"Connection: close" CRLF
CRLF
"4";

MockStream stream(request);
Application app;

app.post("/", &readCountHandler);
app.process(&stream);

assertEqual(expected, stream.response());
}


unittest(buffered_read_count) {
const char *request =
"POST / HTTP/1.0" CRLF
"Content-Length: 4" CRLF
CRLF
"body";

const char *expected =
"HTTP/1.1 200 OK" CRLF
"Content-Type: text/plain" CRLF
Expand Down

0 comments on commit db60f60

Please sign in to comment.