taskrambler  0.1.9
Web server and task management solution.
add_common_header.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2012 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <sys/types.h>
24 
25 #include "class.h"
26 
27 #include "http/message.h"
28 #include "http/header.h"
29 #include "http/worker.h"
30 
31 #include "hash.h"
32 
33 #include "utils/memory.h"
34 #include "utils/http.h"
35 
36 #include "config.h"
37 
38 
39 void
40 httpWorkerAddCommonHeader(HttpWorker this)
41 {
42  char buffer[200];
43  size_t nbuf;
44 
45  if (httpMessageHasKeepAlive((HttpMessage)this->current_request)) {
46  hashAdd(this->current_response->header,
47  new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive")));
48  }
49  else {
50  hashAdd(this->current_response->header,
51  new(HttpHeader, CSTRA("Connection"), CSTRA("Close")));
52  }
53 
54  hashAdd(this->current_response->header,
55  new(HttpHeader, CSTRA("Server"), CSTRA(PACKAGE_STRING)));
56 
57  switch(((HttpResponse)this->current_response)->status) {
58  case 304:
59  break;
60 
61  default:
62  nbuf = sprintf(buffer, "%d", this->current_response->nbody);
63  hashAdd(this->current_response->header,
64  new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf));
65  }
66 
67  nbuf = rfc1123GmtNow(buffer, sizeof(buffer));
68  hashAdd(this->current_response->header,
69  new(HttpHeader, CSTRA("Date"), buffer, nbuf));
70 }
71 
72 // vim: set ts=4 sw=4:
void httpWorkerAddCommonHeader(HttpWorker this)
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
void * hashAdd(Hash, void *)
Definition: add.c:48
size_t rfc1123GmtNow(char *, size_t)
Definition: utils/http.c:69
char httpMessageHasKeepAlive(HttpMessage)