Skip to content

Commit 80eb53b

Browse files
committed
Added testScript for chunked
1 parent fa8f119 commit 80eb53b

File tree

2 files changed

+71
-14
lines changed

2 files changed

+71
-14
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <arpa/inet.h>
2+
#include <netdb.h>
3+
#include <netinet/in.h>
4+
#include <sys/socket.h>
5+
#include <sys/types.h>
6+
#include <unistd.h>
7+
8+
#include <iostream>
9+
#include <sstream>
10+
#include <vector>
11+
12+
void write(int fd, std::string data) {
13+
::write(fd, data.c_str(), data.size());
14+
std::cout << data;
15+
}
16+
17+
int main(int, char **, char **) {
18+
int fd;
19+
20+
struct sockaddr_in addr;
21+
struct sockaddr_in cmp;
22+
23+
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
24+
addr.sin_port = htons(8080);
25+
addr.sin_family = AF_INET;
26+
fd = socket(AF_INET, SOCK_STREAM, 0);
27+
if (fd == -1) {
28+
std::cerr << "error: socket\n";
29+
}
30+
if (connect(fd, (sockaddr *)(&addr), sizeof(addr)) == -1) {
31+
std::cerr << "error: connect\n";
32+
}
33+
std::cout << "connected to: 127.0.0.1:8080" << std::endl;
34+
std::string msg;
35+
msg += "POST /listing/cgi/dump.php HTTP/1.1\r\n";
36+
msg += "Host: 127.0.0.1\r\n";
37+
msg += "Transfer-Encoding: chunked\r\n";
38+
msg += "\r\n";
39+
40+
std::vector<std::string> body;
41+
body.push_back("hello=world");
42+
body.push_back("&bla=blup");
43+
body.push_back("&newline=some text with a newline\r\nin the middle");
44+
45+
std::vector<std::string> trailer;
46+
trailer.push_back("Content-Type: application/x-www-form-urlencoded\r\n");
47+
trailer.push_back("Connection: close\r\n");
48+
// body.push_back("does it\r\n");
49+
// body.push_back("work ???????????????????????????????????");
50+
51+
write(fd, msg.c_str());
52+
53+
for (size_t i = 0; i < body.size(); ++i) {
54+
std::stringstream ss;
55+
ss << std::hex << body[i].size() << "\r\n";
56+
std::string size(ss.str());
57+
write(fd, size);
58+
write(fd, body[i]);
59+
write(fd, "\r\n");
60+
}
61+
write(fd, "0\r\n", 3);
62+
for (size_t i = 0; i < trailer.size(); ++i) write(fd, trailer[i]);
63+
write(fd, "\r\n");
64+
char c;
65+
while (read(fd, &c, 1) == 1) {
66+
std::cout << c;
67+
std::cout.flush();
68+
}
69+
close(fd);
70+
return 0;
71+
}

websites/config_test/listing/putChunked.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)