You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:53:22 UTC
[45/50] git commit: COUCHDB-627 - Support all timezones
COUCHDB-627 - Support all timezones
Some timezones are incorrectly handled by OTP's calendar module. The
ironic thing is that we only ever need the time in GMT (for HTTP
response headers and the log file).
This patch duplicates httpd_util:rfc1123_date/0 and /1 but uses
universal time everywhere, avoiding the broken conversion code.
Also relates to COUCHDB-1513, a duplicate of COUCHDB-627.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/9ad72615
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/9ad72615
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/9ad72615
Branch: refs/heads/import
Commit: 9ad72615cb8ff29f0e379f92ffa92ecc13634b06
Parents: 80571b9
Author: Robert Newson <rn...@apache.org>
Authored: Wed Aug 15 12:34:48 2012 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jan 17 14:51:27 2014 -0800
----------------------------------------------------------------------
src/mochiweb_cookies.erl | 12 ++++++------
src/mochiweb_request.erl | 6 +++---
2 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/9ad72615/src/mochiweb_cookies.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_cookies.erl b/src/mochiweb_cookies.erl
index c090b71..1901d5e 100644
--- a/src/mochiweb_cookies.erl
+++ b/src/mochiweb_cookies.erl
@@ -49,9 +49,9 @@ cookie(Key, Value, Options) ->
RawAge ->
When = case proplists:get_value(local_time, Options) of
undefined ->
- calendar:local_time();
+ calendar:universal_time();
LocalTime ->
- LocalTime
+ calendar:local_time_to_universal_time_dst(LocalTime)
end,
Age = case RawAge < 0 of
true ->
@@ -115,12 +115,12 @@ quote(V0) ->
orelse erlang:error({cookie_quoting_required, V}),
V.
-add_seconds(Secs, LocalTime) ->
- Greg = calendar:datetime_to_gregorian_seconds(LocalTime),
+add_seconds(Secs, UniversalTime) ->
+ Greg = calendar:datetime_to_gregorian_seconds(UniversalTime),
calendar:gregorian_seconds_to_datetime(Greg + Secs).
-age_to_cookie_date(Age, LocalTime) ->
- httpd_util:rfc1123_date(add_seconds(Age, LocalTime)).
+age_to_cookie_date(Age, UniversalTime) ->
+ couch_util:rfc1123_date(add_seconds(Age, UniversalTime)).
%% @spec parse_cookie(string()) -> [{K::string(), V::string()}]
%% @doc Parse the contents of a Cookie header field, ignoring cookie
http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/9ad72615/src/mochiweb_request.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_request.erl b/src/mochiweb_request.erl
index 8225778..2bc54c0 100644
--- a/src/mochiweb_request.erl
+++ b/src/mochiweb_request.erl
@@ -600,9 +600,9 @@ maybe_redirect(RelPath, FullPath, ExtraHeaders) ->
end.
maybe_serve_file(File, ExtraHeaders) ->
- case file:read_file_info(File) of
+ case file:read_file_info(File, [{time, universal}]) of
{ok, FileInfo} ->
- LastModified = httpd_util:rfc1123_date(FileInfo#file_info.mtime),
+ LastModified = couch_util:rfc1123_date(FileInfo#file_info.mtime),
case get_header_value("if-modified-since") of
LastModified ->
respond({304, ExtraHeaders, ""});
@@ -626,7 +626,7 @@ maybe_serve_file(File, ExtraHeaders) ->
server_headers() ->
[{"Server", "MochiWeb/1.0 (" ++ ?QUIP ++ ")"},
- {"Date", httpd_util:rfc1123_date()}].
+ {"Date", couch_util:rfc1123_date()}].
make_code(X) when is_integer(X) ->
[integer_to_list(X), [" " | httpd_util:reason_phrase(X)]];