void finalize(void) { EXTRA_ASSERT(!finalized); finalized = TRUE; GString *buf = g_string_sized_new(256); // Set the status line g_string_append_printf(buf, "%s %d %s\r\n", r->request->version, code, msg); g_string_append_printf(buf, "Server: oio-proxy/%s\r\n", OIOSDS_PROJECT_VERSION); if (0 == g_ascii_strcasecmp("HTTP/1.1", r->request->version)) { // Manage the "Connection" header of http/1.1 gchar *v = g_tree_lookup(r->request->tree_headers, "connection"); if (v && 0 == g_ascii_strcasecmp("Keep-Alive", v)) { g_string_append(buf, "Connection: Keep-Alive\r\n"); r->close_after_request = FALSE; } else { g_string_append(buf, "Connection: Close\r\n"); r->close_after_request = TRUE; } } gsize body_len = body ? g_bytes_get_size(body) : 0; // Add body-related headers if (body_len) { if (content_type) g_string_append_printf(buf, "Content-Type: %s\r\n", content_type); g_string_append(buf, "Transfer-Encoding: identity\r\n"); } g_string_append_printf(buf, "Content-Length: %"G_GSIZE_FORMAT"\r\n", body_len); // Add Custom headers g_tree_foreach(headers, sender, buf); // Finalize and send the headers g_string_append(buf, "\r\n"); network_client_send_slab(r->client, data_slab_make_gstr(buf)); // Now send the body if (body) network_client_send_slab(r->client, data_slab_make_gbytes(body)); body = NULL; _access_log(r, code, body_len, access); }
void network_client_close_output(struct network_client_s *clt, int now) { EXTRA_ASSERT(clt != NULL); if (clt->fd < 0) return; if (!(clt->flags & NETCLIENT_OUT_CLOSED)) { GRID_DEBUG("fd=%d Closing output", clt->fd); if (!now) { if (!(clt->flags & NETCLIENT_OUT_CLOSE_PENDING)) { network_client_send_slab(clt, data_slab_make_eof()); clt->flags |= NETCLIENT_OUT_CLOSE_PENDING; } } else { clt->flags |= NETCLIENT_OUT_CLOSED; data_slab_sequence_clean_data(&(clt->output)); } } }