Skip to content

Commit 7a7c820

Browse files
committed
I believe this does not break the http_load_test, adds URL argument
1 parent 2353808 commit 7a7c820

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

‎examples/http_load_test.c‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const int SSL = 1;
77
#include <stdlib.h>
88
#include <string.h>
99

10-
char request_template[] = "GET / HTTP/1.1\r\nHost: localhost:3000\r\nUser-Agent: curl/7.68.0\r\nAccept: */*\r\n\r\n";
11-
char request_template_post[] = "POST / HTTP/1.1\r\nHost: localhost:3000\r\nUser-Agent: curl/7.68.0\r\nAccept: */*\r\nContent-Length: 10\r\n\r\n{\"key\":13}";
10+
char request_template[] = "GET %s HTTP/1.1\r\nHost: localhost:3000\r\nUser-Agent: curl/7.68.0\r\nAccept: */*\r\n\r\n";
11+
char request_template_post[] = "POST %s HTTP/1.1\r\nHost: localhost:3000\r\nUser-Agent: curl/7.68.0\r\nAccept: */*\r\nContent-Length: 10\r\n\r\n{\"key\":13}";
1212

1313
char *request;
1414
int request_size;
@@ -49,7 +49,7 @@ struct us_socket_t *on_http_socket_writable(struct us_socket_t *s) {
4949
}
5050

5151
struct us_socket_t *on_http_socket_close(struct us_socket_t *s, int code, void *reason) {
52-
return s;
52+
return s;
5353
}
5454

5555
struct us_socket_t *on_http_socket_end(struct us_socket_t *s) {
@@ -117,26 +117,32 @@ struct us_socket_t *on_http_socket_connect_error(struct us_socket_t *s, int code
117117
int main(int argc, char **argv) {
118118

119119
/* Parse host and port */
120-
if (argc != 5 && argc != 4 && argc != 6) {
121-
printf("Usage: connections host port [pipeline factor] [with body]\n");
120+
if (argc < 4 || argc > 7) {
121+
printf("Usage: connections host port [path] [pipeline factor] [with body]\n");
122122
return 0;
123123
}
124124

125-
if (argc >= 5) {
126-
pipeline = atoi(argv[4]);
125+
const char *path = (argc >= 5) ? argv[4] : "/";
126+
127+
if (argc >= 6) {
128+
pipeline = atoi(argv[5]);
127129
printf("Using pipeline factor of %d\n", pipeline);
128130
}
129131

130-
const char *selected_request = request_template;
131-
int selected_request_size = sizeof(request_template) - 1;
132-
133-
if (argc >= 6) {
134-
is_post = atoi(argv[5]);
135-
printf("Using post with body\n");
132+
const char *tmpl = request_template;
133+
char formatted_request[1024];
136134

137-
selected_request = request_template_post;
138-
selected_request_size = sizeof(request_template_post) - 1;
135+
if (argc >= 7) {
136+
is_post = atoi(argv[6]);
137+
if (is_post) {
138+
printf("Using post with body\n");
139+
tmpl = request_template_post;
140+
}
139141
}
142+
143+
int selected_request_size = sprintf(formatted_request, tmpl, path);
144+
const char *selected_request = formatted_request;
145+
140146
/* Pipeline to 16 */
141147
request_size = pipeline * selected_request_size;
142148
printf("request size %d\n", request_size);
@@ -161,9 +167,9 @@ int main(int argc, char **argv) {
161167
struct us_socket_context_t *http_context = us_create_socket_context(SSL, loop, 0, options);
162168

163169
if (!http_context) {
164-
printf("Could not load SSL cert/key\n");
165-
exit(0);
166-
}
170+
printf("Could not load SSL cert/key\n");
171+
exit(0);
172+
}
167173

168174
/* Set up event handlers */
169175
us_socket_context_on_open(SSL, http_context, on_http_socket_open);
@@ -184,4 +190,4 @@ int main(int argc, char **argv) {
184190

185191
us_socket_context_free(SSL, http_context);
186192
us_loop_free(loop);
187-
}
193+
}

0 commit comments

Comments
 (0)