diff --git a/src/network/connection.c b/src/network/connection.c index 52b57620..198beaa6 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -724,6 +724,9 @@ abort_connection(struct connection *conn, enum connection_state state) assertm(is_in_result_state(state), "connection didn't end in result state (%d)", state); + if (state == S_OK && conn->cached) + normalize_cache_entry(conn->cached, conn->from); + set_connection_state(conn, state); if (conn->running) interrupt_connection(conn); diff --git a/src/protocol/about.c b/src/protocol/about.c index e9c5cbf5..7cfe8317 100644 --- a/src/protocol/about.c +++ b/src/protocol/about.c @@ -114,8 +114,6 @@ about_protocol_handler(struct connection *conn) } #endif - normalize_cache_entry(cached, len); - /* Set content to known type */ mem_free_set(&cached->content_type, stracpy("text/html")); } diff --git a/src/protocol/data.c b/src/protocol/data.c index 603f59a9..cd5b4900 100644 --- a/src/protocol/data.c +++ b/src/protocol/data.c @@ -157,7 +157,6 @@ data_protocol_handler(struct connection *conn) int datalen = strlen(data); add_fragment(cached, conn->from, data, datalen); - normalize_cache_entry(cached, datalen); } mem_free(data); diff --git a/src/protocol/file/file.c b/src/protocol/file/file.c index 764935ba..8d593424 100644 --- a/src/protocol/file/file.c +++ b/src/protocol/file/file.c @@ -279,6 +279,7 @@ file_protocol_handler(struct connection *connection) } else { add_fragment(cached, 0, page.source, page.length); + connection->from += page.length; if (!cached->content_type) { unsigned char *ctype = null_or_stracpy(type); @@ -287,15 +288,10 @@ file_protocol_handler(struct connection *connection) * allocation. */ if (type && !ctype) state = S_OUT_OF_MEM; - else - normalize_cache_entry(cached, page.length); /* Setup file read or directory listing for * viewing. */ mem_free_set(&cached->content_type, ctype); - - } else { - normalize_cache_entry(cached, page.length); } done_string(&page); diff --git a/src/protocol/finger/finger.c b/src/protocol/finger/finger.c index f53ad994..6f09b728 100644 --- a/src/protocol/finger/finger.c +++ b/src/protocol/finger/finger.c @@ -27,15 +27,6 @@ struct module finger_protocol_module = struct_module( /* done: */ NULL ); -static void -finger_end_request(struct connection *conn, enum connection_state state) -{ - if (state == S_OK && conn->cached) - normalize_cache_entry(conn->cached, conn->from); - - abort_connection(conn, state); -} - static void finger_get_response(struct socket *socket, struct read_buffer *rb) { @@ -50,7 +41,7 @@ finger_get_response(struct socket *socket, struct read_buffer *rb) conn->cached = cached; if (socket->state == SOCKET_CLOSED) { - finger_end_request(conn, S_OK); + abort_connection(conn, S_OK); return; } diff --git a/src/protocol/fsp/fsp.c b/src/protocol/fsp/fsp.c index 6e785ae6..8e2f3978 100644 --- a/src/protocol/fsp/fsp.c +++ b/src/protocol/fsp/fsp.c @@ -232,8 +232,6 @@ fsp_got_data(struct socket *socket, struct read_buffer *rb) } if (!len) { - if (conn->from) - normalize_cache_entry(conn->cached, conn->from); abort_connection(conn, S_OK); return; } diff --git a/src/protocol/gopher/gopher.c b/src/protocol/gopher/gopher.c index c1d8781b..b89961f9 100644 --- a/src/protocol/gopher/gopher.c +++ b/src/protocol/gopher/gopher.c @@ -346,7 +346,6 @@ end_gopher_connection(struct connection *conn, enum connection_state state) conn->from -= 3; } #endif - normalize_cache_entry(conn->cached, conn->from); } abort_connection(conn, state); diff --git a/src/protocol/http/http.c b/src/protocol/http/http.c index 3efcdef5..d05a99d9 100644 --- a/src/protocol/http/http.c +++ b/src/protocol/http/http.c @@ -470,14 +470,12 @@ http_end_request(struct connection *conn, enum connection_state state, { shutdown_connection_stream(conn); - if (state == S_OK && conn->cached) { - normalize_cache_entry(conn->cached, !notrunc ? conn->from : -1); - } - if (conn->info && !((struct http_connection_info *) conn->info)->close && (!conn->socket->ssl) /* We won't keep alive ssl connections */ && (!get_opt_bool("protocol.http.bugs.post_no_keepalive") || !conn->uri->post)) { + if (state == S_OK && conn->cached) + normalize_cache_entry(conn->cached, !notrunc ? conn->from : -1); set_connection_state(conn, state); add_keepalive_connection(conn, HTTP_KEEPALIVE_TIMEOUT, NULL); } else { diff --git a/src/protocol/smb/smb.c b/src/protocol/smb/smb.c index 62550e31..d8b4a93e 100644 --- a/src/protocol/smb/smb.c +++ b/src/protocol/smb/smb.c @@ -475,10 +475,8 @@ end_smb_connection(struct connection *conn) if (smb_get_cache(conn)) return; - if (conn->from) { - normalize_cache_entry(conn->cached, conn->from); + if (conn->from) goto bye; - } /* Ensure termination by LF + NUL chars, memory for this * was reserved by smb_read_text(). */ @@ -507,7 +505,6 @@ end_smb_connection(struct connection *conn) add_fragment(conn->cached, 0, page.source, page.length); conn->from += page.length; - normalize_cache_entry(conn->cached, page.length); done_string(&page); mem_free_set(&conn->cached->content_type, stracpy("text/html"));