Commit e0abf3ac919ffecd891d7b7d3a4dd1c79646077b
1 parent
f93d09b5
now every date header is formatted in GMT. Commment: We still have a very weak Etag implementation.
Showing
4 changed files
with
49 additions
and
19 deletions
... | ... | @@ -23,10 +23,13 @@ |
23 | 23 | #ifndef __UTILS_HTTP_H__ |
24 | 24 | #define __UTILS_HTTP_H__ |
25 | 25 | |
26 | +#include <time.h> | |
26 | 27 | #include <sys/types.h> |
27 | 28 | |
28 | 29 | #include "http/message.h" |
29 | 30 | |
31 | +size_t rfc1123Gmt(char *, size_t, const time_t *); | |
32 | +size_t rfc1123GmtNow(char *, size_t); | |
30 | 33 | char isHttpVersion(const char *, size_t); |
31 | 34 | HttpMessage httpGetMessage( |
32 | 35 | const char *, size_t, | ... | ... |
... | ... | @@ -43,6 +43,7 @@ |
43 | 43 | |
44 | 44 | #include "utils/mime_type.h" |
45 | 45 | #include "utils/hash.h" |
46 | +#include "utils/http.h" | |
46 | 47 | |
47 | 48 | |
48 | 49 | static |
... | ... | @@ -74,8 +75,10 @@ assetCtor(void * _this, va_list * params) |
74 | 75 | |
75 | 76 | tmp = localtime(&(st.st_mtime)); |
76 | 77 | this->netag = strftime(this->etag, sizeof(this->etag), "%s", tmp); |
77 | - this->nmtime = strftime( | |
78 | - this->mtime, sizeof(this->mtime), "%a, %d %b %Y %T %Z", tmp); | |
78 | + this->nmtime = rfc1123Gmt( | |
79 | + this->mtime, | |
80 | + sizeof(this->mtime), | |
81 | + &(st.st_mtime)); | |
79 | 82 | |
80 | 83 | this->size = st.st_size; |
81 | 84 | ... | ... |
... | ... | @@ -20,7 +20,6 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | -#include <time.h> | |
24 | 23 | #include <sys/types.h> |
25 | 24 | |
26 | 25 | #include "class.h" |
... | ... | @@ -29,23 +28,17 @@ |
29 | 28 | #include "http/header.h" |
30 | 29 | #include "http/response.h" |
31 | 30 | |
32 | -#include "utils/memory.h" | |
33 | 31 | #include "hash.h" |
34 | 32 | |
35 | -static const char *DAY_NAMES[] = { | |
36 | - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; | |
37 | -static const char *MONTH_NAMES[] = { | |
38 | - "Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
39 | - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | |
33 | +#include "utils/memory.h" | |
34 | +#include "utils/http.h" | |
40 | 35 | |
41 | 36 | |
42 | 37 | void |
43 | 38 | httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response) |
44 | 39 | { |
45 | - time_t t; | |
46 | - struct tm * tmp; | |
47 | - char buffer[200]; | |
48 | - size_t nbuf; | |
40 | + char buffer[200]; | |
41 | + size_t nbuf; | |
49 | 42 | |
50 | 43 | if (httpMessageHasKeepAlive(request)) { |
51 | 44 | hashAdd(response->header, |
... | ... | @@ -69,12 +62,7 @@ httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response) |
69 | 62 | new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf)); |
70 | 63 | } |
71 | 64 | |
72 | - t = time(NULL); | |
73 | - tmp = gmtime(&t); | |
74 | - nbuf = strftime(buffer, sizeof(buffer), "---, %d --- %Y %T GMT", tmp); | |
75 | - memcpy(buffer, DAY_NAMES[tmp->tm_wday], 3); | |
76 | - memcpy(buffer+8, MONTH_NAMES[tmp->tm_mon], 3); | |
77 | - | |
65 | + nbuf = rfc1123GmtNow(buffer, sizeof(buffer)); | |
78 | 66 | hashAdd(response->header, |
79 | 67 | new(HttpHeader, CSTRA("Date"), buffer, nbuf)); |
80 | 68 | } | ... | ... |
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | +#include <time.h> | |
23 | 24 | #include <stdlib.h> |
24 | 25 | #include <sys/types.h> |
25 | 26 | #include <string.h> |
... | ... | @@ -32,6 +33,41 @@ |
32 | 33 | |
33 | 34 | #include "commons.h" |
34 | 35 | |
36 | + | |
37 | +static const char *DAY_NAMES[] = { | |
38 | + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; | |
39 | +static const char *MONTH_NAMES[] = { | |
40 | + "Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
41 | + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | |
42 | + | |
43 | + | |
44 | +/* | |
45 | + * This one is not thread save. | |
46 | + */ | |
47 | +size_t | |
48 | +rfc1123Gmt(char * buffer, size_t _nbuf, const time_t * t) | |
49 | +{ | |
50 | + struct tm * tmp = gmtime(t); | |
51 | + size_t nbuf; | |
52 | + | |
53 | + nbuf = strftime(buffer, _nbuf, "---, %d --- %Y %T GMT", tmp); | |
54 | + memcpy(buffer, DAY_NAMES[tmp->tm_wday], 3); | |
55 | + memcpy(buffer+8, MONTH_NAMES[tmp->tm_mon], 3); | |
56 | + | |
57 | + return nbuf; | |
58 | +} | |
59 | + | |
60 | +/* | |
61 | + * This one is not thread save. | |
62 | + */ | |
63 | +size_t | |
64 | +rfc1123GmtNow(char * buffer, size_t _nbuf) | |
65 | +{ | |
66 | + time_t t = time(NULL); | |
67 | + | |
68 | + return rfc1123Gmt(buffer, _nbuf, &t); | |
69 | +} | |
70 | + | |
35 | 71 | char |
36 | 72 | isHttpVersion(const char * str, size_t len) |
37 | 73 | { | ... | ... |
Please
register
or
login
to post a comment