Server 0.0.1
HTTP/REST server implementation

src/http/worker/add_common_header.c

Go to the documentation of this file.
00001 
00023 #include <time.h>
00024 #include <sys/types.h>
00025 
00026 #include "class.h"
00027 
00028 #include "http/message.h"
00029 #include "http/header.h"
00030 #include "http/response.h"
00031 
00032 #include "utils/memory.h"
00033 #include "hash.h"
00034 
00035 void
00036 httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
00037 {
00038         time_t       t;
00039         struct tm *  tmp;
00040         char         buffer[200];
00041         size_t       nbuf;
00042 
00043         if (httpMessageHasKeepAlive(request)) {
00044                 hashAdd(response->header,
00045                                 new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive")));
00046         }
00047         else {
00048                 hashAdd(response->header,
00049                                 new(HttpHeader, CSTRA("Connection"), CSTRA("Close")));
00050         }
00051 
00052         hashAdd(response->header,
00053                         new(HttpHeader, CSTRA("Server"), CSTRA("testserver")));
00054 
00055         switch(((HttpResponse)response)->status) {
00056                 case 304:
00057                         break;
00058 
00059                 default:
00060                         nbuf = sprintf(buffer, "%d", response->nbody);
00061                         hashAdd(response->header,
00062                                         new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf));
00063         }
00064 
00065         t    = time(NULL);
00066         tmp  = localtime(&t);
00067         nbuf = strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp);
00068         hashAdd(response->header,
00069                         new(HttpHeader, CSTRA("Date"), buffer, nbuf));
00070 }
00071 
00072 // vim: set ts=4 sw=4:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines