Simplify print statements by using HTTP_UNPACK
This commit is contained in:
@@ -43,7 +43,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Status: %d\n", result->status);
|
printf("Status: %d\n", result->status);
|
||||||
printf("Body: %.*s\n", (int)result->body.len, result->body.ptr);
|
printf("Body: %.*s\n", HTTP_UNPACK(result->body));
|
||||||
|
|
||||||
http_request_free(reqs[i-1]);
|
http_request_free(reqs[i-1]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,11 +173,11 @@ int main(int argc, char **argv)
|
|||||||
if (url.len == 0) break;
|
if (url.len == 0) break;
|
||||||
|
|
||||||
if (is_already_crawled(url)) {
|
if (is_already_crawled(url)) {
|
||||||
printf("Ignoring " RED "%.*s" RST "\n", (int) url.len, url.ptr);
|
printf("Ignoring " RED "%.*s" RST "\n", HTTP_UNPACK(url));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Fetching " GRN "%.*s" RST "\n", (int) url.len, url.ptr);
|
printf("Fetching " GRN "%.*s" RST "\n", HTTP_UNPACK(url));
|
||||||
add_to_crawled_list(url);
|
add_to_crawled_list(url);
|
||||||
|
|
||||||
HTTP_RequestHandle req;
|
HTTP_RequestHandle req;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ int main(void)
|
|||||||
// sure to express the length when interacting with
|
// sure to express the length when interacting with
|
||||||
// libc:
|
// libc:
|
||||||
HTTP_String path = req->url.path;
|
HTTP_String path = req->url.path;
|
||||||
printf("requested path [%.*s]\n", (int) path.len, path.ptr);
|
printf("requested path [%.*s]\n", HTTP_UNPACK(path));
|
||||||
|
|
||||||
// To find a specific header value, you can either
|
// To find a specific header value, you can either
|
||||||
// iterate over the [req->headers] array or use
|
// iterate over the [req->headers] array or use
|
||||||
@@ -60,7 +60,7 @@ int main(void)
|
|||||||
} else {
|
} else {
|
||||||
// Found
|
// Found
|
||||||
HTTP_String value = req->headers[idx].value;
|
HTTP_String value = req->headers[idx].value;
|
||||||
printf("Header has value [%.*s]\n", (int) value.len, value.ptr);
|
printf("Header has value [%.*s]\n", HTTP_UNPACK(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// To create a response, you will need to specify
|
// To create a response, you will need to specify
|
||||||
|
|||||||
+3
-13
@@ -35,10 +35,7 @@ void testeq_engstate(HTTP_EngineState l, HTTP_EngineState r, HTTP_String uneval_
|
|||||||
{
|
{
|
||||||
if (l != r) {
|
if (l != r) {
|
||||||
printf("Test failed at %s:%d\n", file, line);
|
printf("Test failed at %s:%d\n", file, line);
|
||||||
printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%s, %s)\n",
|
printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%s, %s)\n", HTTP_UNPACK(uneval_l), HTTP_UNPACK(uneval_r), statestr(l), statestr(r));
|
||||||
(int) uneval_l.len, uneval_l.ptr,
|
|
||||||
(int) uneval_r.len, uneval_r.ptr,
|
|
||||||
statestr(l), statestr(r));
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,10 +44,7 @@ void testeq_int(int l, int r, HTTP_String uneval_l, HTTP_String uneval_r, const
|
|||||||
{
|
{
|
||||||
if (l != r) {
|
if (l != r) {
|
||||||
printf("Test failed at %s:%d\n", file, line);
|
printf("Test failed at %s:%d\n", file, line);
|
||||||
printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%d, %d)\n",
|
printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%d, %d)\n", HTTP_UNPACK(uneval_l), HTTP_UNPACK(uneval_r), l, r);
|
||||||
(int) uneval_l.len, uneval_l.ptr,
|
|
||||||
(int) uneval_r.len, uneval_r.ptr,
|
|
||||||
l, r);
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,11 +53,7 @@ void testeq_str(HTTP_String l, HTTP_String r, HTTP_String uneval_l, HTTP_String
|
|||||||
{
|
{
|
||||||
if (!http_streq(l, r)) {
|
if (!http_streq(l, r)) {
|
||||||
printf("Test failed at %s:%d\n", file, line);
|
printf("Test failed at %s:%d\n", file, line);
|
||||||
printf(" TEST_EQ(\"%.*s\", \"%.*s\") -> TEST_EQ(%.*s, %.*s)\n",
|
printf(" TEST_EQ(\"%.*s\", \"%.*s\") -> TEST_EQ(%.*s, %.*s)\n", HTTP_UNPACK(uneval_l), HTTP_UNPACK(uneval_r), HTTP_UNPACK(l), HTTP_UNPACK(r));
|
||||||
(int) uneval_l.len, uneval_l.ptr,
|
|
||||||
(int) uneval_r.len, uneval_r.ptr,
|
|
||||||
(int) l.len, l.ptr,
|
|
||||||
(int) r.len, r.ptr);
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user