mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 23:49:44 +08:00
Enhance HTTP client example
This commit is contained in:
parent
66f302a613
commit
6bcd02bb1c
@ -9,19 +9,23 @@
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_url = "https://cesanta.com";
|
||||
// The very first web page in history
|
||||
static const char *s_url = "http://info.cern.ch";
|
||||
|
||||
// Print HTTP response and signal that we're done
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_CONNECT) {
|
||||
// Connected to server
|
||||
struct mg_str host = mg_url_host(s_url);
|
||||
|
||||
if (mg_url_is_ssl(s_url)) {
|
||||
// If s_url is https://, tell client connection to use TLS
|
||||
struct mg_tls_opts opts = {.ca = "ca.pem"};
|
||||
mg_tls_init(c, &opts);
|
||||
}
|
||||
// Send request
|
||||
mg_printf(c, "GET %s HTTP/1.0\r\n\r\n", mg_url_uri(s_url));
|
||||
mg_printf(c, "GET %s HTTP/1.0\r\nHost: %.*s\r\n\r\n", mg_url_uri(s_url),
|
||||
(int) host.len, host.ptr);
|
||||
} else if (ev == MG_EV_HTTP_MSG) {
|
||||
// Response is received. Print it
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
|
@ -223,7 +223,7 @@ bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) {
|
||||
atype = ((int) s[j - 8] << 8) | s[j - 7];
|
||||
aclass = ((int) s[j - 6] << 8) | s[j - 5];
|
||||
n = ((int) s[j] << 8) | s[j + 1];
|
||||
LOG(LL_DEBUG, ("%s %d %hu %hu", dm->name, (int) n, atype, aclass));
|
||||
LOG(LL_VERBOSE_DEBUG, ("%s %d %hu %hu", dm->name, (int) n, atype, aclass));
|
||||
if (&s[j] + 2 + n > e) break;
|
||||
if (n == 4 && atype == 1 && aclass == 1) {
|
||||
dm->addr.is_ip6 = false;
|
||||
@ -259,7 +259,7 @@ static void dns_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
LOG(LL_ERROR, ("Unexpected DNS response:\n%s\n", s));
|
||||
free(s);
|
||||
} else {
|
||||
LOG(LL_DEBUG, ("%s %d", dm.name, dm.resolved));
|
||||
LOG(LL_VERBOSE_DEBUG, ("%s %d", dm.name, dm.resolved));
|
||||
for (d = s_reqs; d != NULL; d = tmp) {
|
||||
tmp = d->next;
|
||||
// LOG(LL_INFO, ("d %p %hu %hu", d, d->txnid, dm.txnid));
|
||||
|
Loading…
x
Reference in New Issue
Block a user