From: Brian Pane Date: Sun, 21 Apr 2002 07:55:50 +0000 (+0000) Subject: Added ap_recent_rfc822_date(), which uses the recent timestamp cache X-Git-Tag: 2.0.36~132 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=166b62f9c5d52727e950db8e9160184fdc6c8b63;p=apache Added ap_recent_rfc822_date(), which uses the recent timestamp cache Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94735 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/util_time.h b/include/util_time.h index b69aadc759..00cacf6cf5 100644 --- a/include/util_time.h +++ b/include/util_time.h @@ -109,6 +109,13 @@ AP_DECLARE(apr_status_t) ap_explode_recent_gmt(apr_time_exp_t *tm, */ AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t); +/** + * format a recent timestamp in the RFC822 format + * @param date_str String to write to (must have length >= APR_RFC822_DATE_LEN) + * @param t the time to convert + */ +AP_DECLARE(apr_status_t) ap_recent_rfc822_date(char *date_str, apr_time_t t); + #ifdef __cplusplus } #endif diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 331a4a55f9..84c171873e 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -89,6 +89,7 @@ #include "apr_date.h" /* For apr_date_parse_http and APR_DATE_BAD */ #include "util_charset.h" #include "util_ebcdic.h" +#include "util_time.h" #include "mod_core.h" @@ -1071,7 +1072,7 @@ static void basic_http_header(request_rec *r, apr_bucket_brigade *bb, apr_brigade_write(bb, NULL, NULL, tmp, len); date = apr_palloc(r->pool, APR_RFC822_DATE_LEN); - apr_rfc822_date(date, r->request_time); + ap_recent_rfc822_date(date, r->request_time); h.pool = r->pool; h.bb = bb; @@ -1444,7 +1445,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, */ if (r->no_cache && !apr_table_get(r->headers_out, "Expires")) { char *date = apr_palloc(r->pool, APR_RFC822_DATE_LEN); - apr_rfc822_date(date, r->request_time); + ap_recent_rfc822_date(date, r->request_time); apr_table_addn(r->headers_out, "Expires", date); } diff --git a/server/util_time.c b/server/util_time.c index 7a0880953b..ec9400de40 100644 --- a/server/util_time.c +++ b/server/util_time.c @@ -218,3 +218,63 @@ AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t) return APR_SUCCESS; } + +static const char month_snames[12][4] = +{ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; +static const char day_snames[7][4] = +{ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +AP_DECLARE(apr_status_t) ap_recent_rfc822_date(char *date_str, apr_time_t t) +{ + /* ### This code is a clone of apr_rfc822_date(), except that it + * uses ap_explode_recent_gmt() instead of apr_time_exp_gmt(). + */ + apr_time_exp_t xt; + const char *s; + int real_year; + + ap_explode_recent_gmt(&xt, t); + + /* example: "Sat, 08 Jan 2000 18:31:41 GMT" */ + /* 12345678901234567890123456789 */ + + s = &day_snames[xt.tm_wday][0]; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = ','; + *date_str++ = ' '; + *date_str++ = xt.tm_mday / 10 + '0'; + *date_str++ = xt.tm_mday % 10 + '0'; + *date_str++ = ' '; + s = &month_snames[xt.tm_mon][0]; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = ' '; + real_year = 1900 + xt.tm_year; + /* This routine isn't y10k ready. */ + *date_str++ = real_year / 1000 + '0'; + *date_str++ = real_year % 1000 / 100 + '0'; + *date_str++ = real_year % 100 / 10 + '0'; + *date_str++ = real_year % 10 + '0'; + *date_str++ = ' '; + *date_str++ = xt.tm_hour / 10 + '0'; + *date_str++ = xt.tm_hour % 10 + '0'; + *date_str++ = ':'; + *date_str++ = xt.tm_min / 10 + '0'; + *date_str++ = xt.tm_min % 10 + '0'; + *date_str++ = ':'; + *date_str++ = xt.tm_sec / 10 + '0'; + *date_str++ = xt.tm_sec % 10 + '0'; + *date_str++ = ' '; + *date_str++ = 'G'; + *date_str++ = 'M'; + *date_str++ = 'T'; + *date_str++ = 0; + return APR_SUCCESS; +}