Skip to content
This repository

Patch to cowboy_rest for when local time != UTC #282

Closed
wants to merge 1 commit into from

3 participants

dbmercer Loïc Hoguin Vladimir Dronnikov
dbmercer

The If-Modified-Since and Last-Modified HTTP headers are in UTC, but cowboy_rest.erl is expecting the time returned by last_modified/1 to be in local time. (We know this because the Last-Modified header is assembled with httpd_util:rfc1123_date/1, which expects its argument in local time.) When comparing the If-Modified-Since time to last_modified, we therefore need to put them in the same timezone.

Loïc Hoguin
Owner

Hey, what I want is to actually standardize everything on UTC and allow developers to not worry about the timezones unless seriously needed.

dbmercer
Loïc Hoguin
Owner

Hey, forgot to reply! Sorry.

If you are willing to switch all local time code (should be this, cookies has something, there's a function in cowboy_clock which expects local time too), then please do! Tell me otherwise I want to fix that shortly.

Thanks!

Loïc Hoguin
Owner

I'll start taking a look.

dbmercer
Loïc Hoguin
Owner

I just got annoyed with that code. I want GMT everywhere. :)

I'll probably take the opportunity to rewrite cookies.

Vladimir Dronnikov

+1 for GMT only

Loïc Hoguin
Owner

Almost done with that. Will push tomorrow.

Loïc Hoguin
Owner

Should be good with 27da092. The REST part was done in #305.

Thanks!

Loïc Hoguin essen closed this December 07, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 11, 2012
Modified cowboy_rest to work appropriately when local time != UTC 78394c2
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. 10  src/cowboy_rest.erl
10  src/cowboy_rest.erl
@@ -570,9 +570,13 @@ if_modified_since(Req, State, IfModifiedSince) ->
570 570
 		no_call ->
571 571
 			method(Req2, State2);
572 572
 		LastModified ->
573  
-			case LastModified > IfModifiedSince of
574  
-				true -> method(Req2, State2);
575  
-				false -> not_modified(Req2, State2)
  573
+			case calendar:local_time_to_universal_time_dst(LastModified) of
  574
+				[] -> method(Req2, State2);
  575
+				[LastModifiedUtc | _] ->
  576
+					case LastModifiedUtc > IfModifiedSince of
  577
+						true -> method(Req2, State2);
  578
+						false -> not_modified(Req2, State2)
  579
+					end
576 580
 			end
577 581
 	end.
578 582
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.