(send_http_message): Changed the function to use the new http_message

API.
This commit is contained in:
Robert James Kaes 2003-03-14 06:15:27 +00:00
parent c76183a3f0
commit cc90414b29

View File

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.37 2003-03-13 21:34:38 rjkaes Exp $ /* $Id: utils.c,v 1.38 2003-03-14 06:15:27 rjkaes Exp $
* *
* Misc. routines which are used by the various functions to handle strings * Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also, * and memory allocation and pretty much anything else we can think of. Also,
@ -6,7 +6,8 @@
* it, so it's in here. * it, so it's in here.
* *
* Copyright (C) 1998 Steven Young * Copyright (C) 1998 Steven Young
* Copyright (C) 1999,2001 Robert James Kaes (rjkaes@flarenet.com) * Copyright (C) 1999,2001,2003 by
* Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -21,17 +22,11 @@
#include "tinyproxy.h" #include "tinyproxy.h"
#include "buffer.h"
#include "conns.h" #include "conns.h"
#include "filter.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "http_message.h"
#include "network.h"
#include "sock.h"
#include "utils.h" #include "utils.h"
#define HEADER_SIZE (1024 * 8)
/* /*
* Build the data for a complete HTTP & HTML message for the client. * Build the data for a complete HTTP & HTML message for the client.
*/ */
@ -39,30 +34,24 @@ int
send_http_message(struct conn_s *connptr, int http_code, send_http_message(struct conn_s *connptr, int http_code,
const char *error_title, const char *message) const char *error_title, const char *message)
{ {
static char *headers = \ static char* headers[] = {
"HTTP/1.0 %d %s\r\n" \ "Server: " PACKAGE "/" VERSION,
"Server: %s/%s\r\n" \ "Content-type: text/html",
"Date: %s\r\n" \ "Connection: close"
"Content-Type: text/html\r\n" \ };
"Content-Length: %d\r\n" \
"Connection: close\r\n" \
"\r\n";
char timebuf[30]; http_message_t msg;
time_t global_time;
size_t message_len = strlen(message);
global_time = time(NULL); msg = http_message_create(http_code, error_title);
strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", if (msg == NULL)
gmtime(&global_time));
if (write_message(connptr->client_fd,
headers,
http_code, error_title, PACKAGE, VERSION,
timebuf, message_len) < 0)
return -1; return -1;
return safe_write(connptr->client_fd, message, message_len); http_message_add_headers(msg, headers, 3);
http_message_set_body(msg, message, strlen(message));
http_message_send(msg, connptr->client_fd);
http_message_destroy(msg);
return 0;
} }
/* /*