You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

#include <string>
#include "UDPTCPNetwork.h"
int test_fragmentedbuffer() {
std::string buf1;
WebRequestBuffer buffer;
buffer.Clear();
buf1 = "POST /get/newvalues HTTP/1.1\r\n";
buf1 += "Host: localhost:11001\r\n";
buf1 += "Connection: keep-alive\r\n";
buf1 += "Content-Length: 20\r\n";
buf1 += "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36\r\n";
buf1 += "Accept: *//*\r\n";
buf1 += "Origin: http://localhost:11001\r\n";
buf1 += "Sec-Fetch-Site: same-origin\r\n";
buf1 += "Referer: http://localhost:11001/index.html\r\n";
buf1 += "Accept-Encoding: gzip, deflate, br, zstd\r\n";
buf1 += "Accept-Language: de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US;q=0.6\r\n";
buf1 += "\r\n";
buffer.AddBuffer((char*)buf1.c_str(), strlen(buf1.c_str()));
if (buffer.RequestComplete()) {
debug ("header added: request is marked as complete but it isn't");
return 0;
};
buf1 = "0123456789";
buffer.AddBuffer((char*)buf1.c_str(), strlen(buf1.c_str()));
if (buffer.RequestComplete()) {
char *ptr = NULL;
int max = 0;
debug ("first 10 bytes: request is marked as complete but it isn't");
buffer.GetBuffer(&ptr, &max);
debug ("buffer:'%s'", ptr);
return 0;
};
buf1 = "0123456789";
buffer.AddBuffer((char*)buf1.c_str(), strlen(buf1.c_str()));
if (!buffer.RequestComplete()) {
char *ptr = NULL;
int max = 0;
debug ("second 10 bytes: request is not marked as complete but it is");
buffer.GetBuffer(&ptr, &max);
debug ("buffer:'%s'", ptr);
return 0;
};
return 1;
};
int main(int argc, char** argv) {
debug ("test: buffer with fragmented header and content");
if (!test_fragmentedbuffer()) exit(1);
debug ("all tests passed");
return 0;
};