Browse Source

now every date header is formatted in GMT. Commment: We still have a very weak Etag implementation.

release0.1.5
Georg Hopp 12 years ago
parent
commit
e0abf3ac91
  1. 3
      include/utils/http.h
  2. 7
      src/asset/asset.c
  3. 22
      src/http/worker/add_common_header.c
  4. 36
      src/utils/http.c

3
include/utils/http.h

@ -23,10 +23,13 @@
#ifndef __UTILS_HTTP_H__ #ifndef __UTILS_HTTP_H__
#define __UTILS_HTTP_H__ #define __UTILS_HTTP_H__
#include <time.h>
#include <sys/types.h> #include <sys/types.h>
#include "http/message.h" #include "http/message.h"
size_t rfc1123Gmt(char *, size_t, const time_t *);
size_t rfc1123GmtNow(char *, size_t);
char isHttpVersion(const char *, size_t); char isHttpVersion(const char *, size_t);
HttpMessage httpGetMessage( HttpMessage httpGetMessage(
const char *, size_t, const char *, size_t,

7
src/asset/asset.c

@ -43,6 +43,7 @@
#include "utils/mime_type.h" #include "utils/mime_type.h"
#include "utils/hash.h" #include "utils/hash.h"
#include "utils/http.h"
static static
@ -74,8 +75,10 @@ assetCtor(void * _this, va_list * params)
tmp = localtime(&(st.st_mtime)); tmp = localtime(&(st.st_mtime));
this->netag = strftime(this->etag, sizeof(this->etag), "%s", tmp); this->netag = strftime(this->etag, sizeof(this->etag), "%s", tmp);
this->nmtime = strftime(
this->mtime, sizeof(this->mtime), "%a, %d %b %Y %T %Z", tmp);
this->nmtime = rfc1123Gmt(
this->mtime,
sizeof(this->mtime),
&(st.st_mtime));
this->size = st.st_size; this->size = st.st_size;

22
src/http/worker/add_common_header.c

@ -20,7 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <time.h>
#include <sys/types.h> #include <sys/types.h>
#include "class.h" #include "class.h"
@ -29,23 +28,17 @@
#include "http/header.h" #include "http/header.h"
#include "http/response.h" #include "http/response.h"
#include "utils/memory.h"
#include "hash.h" #include "hash.h"
static const char *DAY_NAMES[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char *MONTH_NAMES[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
#include "utils/memory.h"
#include "utils/http.h"
void void
httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response) httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
{ {
time_t t;
struct tm * tmp;
char buffer[200];
size_t nbuf;
char buffer[200];
size_t nbuf;
if (httpMessageHasKeepAlive(request)) { if (httpMessageHasKeepAlive(request)) {
hashAdd(response->header, hashAdd(response->header,
@ -69,12 +62,7 @@ httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf)); new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf));
} }
t = time(NULL);
tmp = gmtime(&t);
nbuf = strftime(buffer, sizeof(buffer), "---, %d --- %Y %T GMT", tmp);
memcpy(buffer, DAY_NAMES[tmp->tm_wday], 3);
memcpy(buffer+8, MONTH_NAMES[tmp->tm_mon], 3);
nbuf = rfc1123GmtNow(buffer, sizeof(buffer));
hashAdd(response->header, hashAdd(response->header,
new(HttpHeader, CSTRA("Date"), buffer, nbuf)); new(HttpHeader, CSTRA("Date"), buffer, nbuf));
} }

36
src/utils/http.c

@ -20,6 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
@ -32,6 +33,41 @@
#include "commons.h" #include "commons.h"
static const char *DAY_NAMES[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char *MONTH_NAMES[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
/*
* This one is not thread save.
*/
size_t
rfc1123Gmt(char * buffer, size_t _nbuf, const time_t * t)
{
struct tm * tmp = gmtime(t);
size_t nbuf;
nbuf = strftime(buffer, _nbuf, "---, %d --- %Y %T GMT", tmp);
memcpy(buffer, DAY_NAMES[tmp->tm_wday], 3);
memcpy(buffer+8, MONTH_NAMES[tmp->tm_mon], 3);
return nbuf;
}
/*
* This one is not thread save.
*/
size_t
rfc1123GmtNow(char * buffer, size_t _nbuf)
{
time_t t = time(NULL);
return rfc1123Gmt(buffer, _nbuf, &t);
}
char char
isHttpVersion(const char * str, size_t len) isHttpVersion(const char * str, size_t len)
{ {

Loading…
Cancel
Save