Skip to content

Commit 45d5aa2

Browse files
authored
[network-protocol][http] prevent premature http transaction handling … (#1001)
[network-protocol][http] prevent premature http transaction handling for HTTP PUT with Headers.
1 parent 652db3a commit 45d5aa2

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/network-protocol/HTTP.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* HTTP implementation
33
*/
44

5+
#define VERBOSE_HTTP 1
6+
#define VERBOSE_PROTOCOL 1
7+
58
#include <cstring>
69

710
#include "HTTP.h"
@@ -440,7 +443,7 @@ bool NetworkProtocolHTTP::status_file(NetworkStatus *status)
440443
{
441444
case DATA:
442445
{
443-
if (!fromInterrupt && resultCode == 0)
446+
if (!fromInterrupt && resultCode == 0 && aux1_open != OPEN_MODE_HTTP_PUT_H)
444447
{
445448
#ifdef VERBOSE_PROTOCOL
446449
Debug_printf("calling http_transaction\r\n");
@@ -558,7 +561,7 @@ bool NetworkProtocolHTTP::close_file_handle()
558561

559562
if (client != nullptr)
560563
{
561-
if (httpOpenMode == PUT)
564+
if (httpOpenMode == PUT || aux1_open == OPEN_MODE_HTTP_PUT_H)
562565
http_transaction();
563566
client->close();
564567
fserror_to_error();
@@ -675,14 +678,14 @@ bool NetworkProtocolHTTP::write_file_handle_send_post_data(uint8_t *buf, unsigne
675678

676679
bool NetworkProtocolHTTP::write_file_handle_data(uint8_t *buf, unsigned short len)
677680
{
678-
if (httpOpenMode != PUT)
681+
if (httpOpenMode == PUT || aux1_open == OPEN_MODE_HTTP_PUT_H)
679682
{
680-
error = NETWORK_ERROR_INVALID_COMMAND;
681-
return true;
683+
postData += std::string((char *)buf, len);
684+
return false; // come back here later.
682685
}
683686

684-
postData += std::string((char *)buf, len);
685-
return false; // come back here later.
687+
error = NETWORK_ERROR_INVALID_COMMAND;
688+
return true;
686689
}
687690

688691
bool NetworkProtocolHTTP::stat()
@@ -738,7 +741,7 @@ void NetworkProtocolHTTP::http_transaction()
738741
resultCode = client->GET();
739742
break;
740743
case POST:
741-
if (aux1_open == 14)
744+
if (aux1_open == OPEN_MODE_HTTP_PUT_H)
742745
resultCode = client->PUT(postData.c_str(), postData.size());
743746
else
744747
resultCode = client->POST(postData.c_str(), postData.size());
@@ -766,6 +769,9 @@ void NetworkProtocolHTTP::http_transaction()
766769

767770
fserror_to_error();
768771
fileSize = bodySize = client->available();
772+
#ifdef VERBOSE_PROTOCOL
773+
Debug_printf("NetworkProtocolHTTP::http_transaction() done, resultCode=%d, fileSize=%u\r\n", resultCode, fileSize);
774+
#endif
769775
}
770776

771777
bool NetworkProtocolHTTP::rename(PeoplesUrlParser *url, cmdFrame_t *cmdFrame)

0 commit comments

Comments
 (0)