Browse Source

Made _CompareResources() easier to read

Pierre-Olivier Latour 10 years ago
parent
commit
9719406303
1 changed files with 9 additions and 5 deletions
  1. 9 5
      GCDWebServer/Core/GCDWebServerConnection.m

+ 9 - 5
GCDWebServer/Core/GCDWebServerConnection.m

@@ -764,15 +764,19 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
   }
 }
 
+// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25
 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26
 static inline BOOL _CompareResources(NSString* responseETag, NSString* requestETag, NSDate* responseLastModified, NSDate* requestLastModified) {
-  if ([requestETag isEqualToString:@"*"] && (!responseLastModified || !requestLastModified || ([responseLastModified compare:requestLastModified] != NSOrderedDescending))) {
-    return YES;
-  } else {
-    if ([responseETag isEqualToString:requestETag]) {
+  if (requestLastModified && responseLastModified) {
+    if ([responseLastModified compare:requestLastModified] != NSOrderedDescending) {
+      return YES;
+    }
+  }
+  if (requestETag && responseETag) {  // Per the specs "If-None-Match" must be checked after "If-Modified-Since"
+    if ([requestETag isEqualToString:@"*"]) {
       return YES;
     }
-    if (responseLastModified && requestLastModified && ([responseLastModified compare:requestLastModified] != NSOrderedDescending)) {
+    if ([responseETag isEqualToString:requestETag]) {
       return YES;
     }
   }