demote most warnings to debug messages;

execute callback later to allow freeing of connection object


svn:r407
This commit is contained in:
Niels Provos 2007-09-02 01:33:38 +00:00
parent 11a0a9e42f
commit ff9e1af68f
2 changed files with 32 additions and 25 deletions

View File

@ -1,2 +1,3 @@
Changes in current version: Changes in current version:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
o demote most http warnings to debug messages

56
http.c
View File

@ -507,6 +507,8 @@ evhttp_connection_fail(struct evhttp_connection *evcon,
enum evhttp_connection_error error) enum evhttp_connection_error error)
{ {
struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); struct evhttp_request* req = TAILQ_FIRST(&evcon->requests);
void (*cb)(struct evhttp_request *, void *);
void *cb_arg;
assert(req != NULL); assert(req != NULL);
if (evcon->flags & EVHTTP_CON_INCOMING) { if (evcon->flags & EVHTTP_CON_INCOMING) {
@ -523,9 +525,9 @@ evhttp_connection_fail(struct evhttp_connection *evcon,
return; return;
} }
/* save the callback for later; the cb might free our object */
if (req->cb != NULL) cb = req->cb;
(*req->cb)(NULL, req->cb_arg); cb_arg = req->cb_arg;
TAILQ_REMOVE(&evcon->requests, req, next); TAILQ_REMOVE(&evcon->requests, req, next);
evhttp_request_free(req); evhttp_request_free(req);
@ -538,6 +540,10 @@ evhttp_connection_fail(struct evhttp_connection *evcon,
/* We are trying the next request that was queued on us */ /* We are trying the next request that was queued on us */
if (TAILQ_FIRST(&evcon->requests) != NULL) if (TAILQ_FIRST(&evcon->requests) != NULL)
evhttp_connection_connect(evcon); evhttp_connection_connect(evcon);
/* inform the user */
if (cb != NULL)
(*cb)(NULL, cb_arg);
} }
void void
@ -553,13 +559,13 @@ evhttp_write(int fd, short what, void *arg)
n = evbuffer_write(evcon->output_buffer, fd); n = evbuffer_write(evcon->output_buffer, fd);
if (n == -1) { if (n == -1) {
event_warn("%s: evbuffer_write", __func__); event_debug(("%s: evbuffer_write", __func__));
evhttp_connection_fail(evcon, EVCON_HTTP_EOF); evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
return; return;
} }
if (n == 0) { if (n == 0) {
event_warnx("%s: write nothing", __func__); event_debug(("%s: write nothing", __func__));
evhttp_connection_fail(evcon, EVCON_HTTP_EOF); evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
return; return;
} }
@ -743,7 +749,7 @@ evhttp_read(int fd, short what, void *arg)
event_debug(("%s: got %d on %d\n", __func__, n, fd)); event_debug(("%s: got %d on %d\n", __func__, n, fd));
if (n == -1) { if (n == -1) {
event_warn("%s: evbuffer_read", __func__); event_debug(("%s: evbuffer_read", __func__));
evhttp_connection_fail(evcon, EVCON_HTTP_EOF); evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
return; return;
} else if (n == 0) { } else if (n == 0) {
@ -904,23 +910,23 @@ evhttp_connectioncb(int fd, short what, void *arg)
socklen_t errsz = sizeof(error); socklen_t errsz = sizeof(error);
if (what == EV_TIMEOUT) { if (what == EV_TIMEOUT) {
event_warnx("%s: connection timeout for \"%s:%d\" on %d", event_debug(("%s: connection timeout for \"%s:%d\" on %d",
__func__, evcon->address, evcon->port, evcon->fd); __func__, evcon->address, evcon->port, evcon->fd));
goto cleanup; goto cleanup;
} }
/* Check if the connection completed */ /* Check if the connection completed */
if (getsockopt(evcon->fd, SOL_SOCKET, SO_ERROR, (void*)&error, if (getsockopt(evcon->fd, SOL_SOCKET, SO_ERROR, (void*)&error,
&errsz) == -1) { &errsz) == -1) {
event_warn("%s: getsockopt for \"%s:%d\" on %d", event_debug(("%s: getsockopt for \"%s:%d\" on %d",
__func__, evcon->address, evcon->port, evcon->fd); __func__, evcon->address, evcon->port, evcon->fd));
goto cleanup; goto cleanup;
} }
if (error) { if (error) {
event_warnx("%s: connect failed for \"%s:%d\" on %d: %s", event_debug(("%s: connect failed for \"%s:%d\" on %d: %s",
__func__, evcon->address, evcon->port, evcon->fd, __func__, evcon->address, evcon->port, evcon->fd,
strerror(error)); strerror(error)));
goto cleanup; goto cleanup;
} }
@ -995,15 +1001,15 @@ evhttp_parse_response_line(struct evhttp_request *req, char *line)
req->major = 1; req->major = 1;
req->minor = 1; req->minor = 1;
} else { } else {
event_warnx("%s: bad protocol \"%s\"", event_debug(("%s: bad protocol \"%s\"",
__func__, protocol); __func__, protocol));
return (-1); return (-1);
} }
req->response_code = atoi(number); req->response_code = atoi(number);
if (!evhttp_valid_response_code(req->response_code)) { if (!evhttp_valid_response_code(req->response_code)) {
event_warnx("%s: bad response code \"%s\"", event_debug(("%s: bad response code \"%s\"",
__func__, number); __func__, number));
return (-1); return (-1);
} }
@ -1041,8 +1047,8 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
} else if (strcmp(method, "HEAD") == 0) { } else if (strcmp(method, "HEAD") == 0) {
req->type = EVHTTP_REQ_HEAD; req->type = EVHTTP_REQ_HEAD;
} else { } else {
event_warnx("%s: bad method %s on request %p from %s", event_debug(("%s: bad method %s on request %p from %s",
__func__, method, req, req->remote_host); __func__, method, req, req->remote_host));
return (-1); return (-1);
} }
@ -1053,13 +1059,13 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
req->major = 1; req->major = 1;
req->minor = 1; req->minor = 1;
} else { } else {
event_warnx("%s: bad version %s on request %p from %s", event_debug(("%s: bad version %s on request %p from %s",
__func__, version, req, req->remote_host); __func__, version, req, req->remote_host));
return (-1); return (-1);
} }
if ((req->uri = strdup(uri)) == NULL) { if ((req->uri = strdup(uri)) == NULL) {
event_warn("%s: evhttp_decode_uri", __func__); event_debug(("%s: evhttp_decode_uri", __func__));
return (-1); return (-1);
} }
@ -1303,12 +1309,12 @@ evhttp_read_header(int fd, short what, void *arg)
n = evbuffer_read(evcon->input_buffer, fd, -1); n = evbuffer_read(evcon->input_buffer, fd, -1);
if (n == 0) { if (n == 0) {
event_warnx("%s: no more data on %d", __func__, fd); event_debug(("%s: no more data on %d", __func__, fd));
evhttp_connection_fail(evcon, EVCON_HTTP_EOF); evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
return; return;
} }
if (n == -1) { if (n == -1) {
event_warnx("%s: bad read on %d", __func__, fd); event_debug(("%s: bad read on %d", __func__, fd));
evhttp_connection_fail(evcon, EVCON_HTTP_EOF); evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
return; return;
} }
@ -1461,8 +1467,8 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
/* Do async connection to HTTP server */ /* Do async connection to HTTP server */
if ((evcon->fd = make_socket( if ((evcon->fd = make_socket(
0, evcon->address, evcon->port)) == -1) { 0, evcon->address, evcon->port)) == -1) {
event_warn("%s: failed to connect to \"%s:%d\"", event_debug(("%s: failed to connect to \"%s:%d\"",
__func__, evcon->address, evcon->port); __func__, evcon->address, evcon->port));
return (-1); return (-1);
} }