[Bbs2ch-cvs 196] [178] ファイルストリームから直接読み込むようにした

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 7月 28日 (土) 02:07:41 JST


Revision: 178
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=178
Author:   flyson
Date:     2007-07-28 02:07:41 +0900 (Sat, 28 Jul 2007)

Log Message:
-----------
ファイルストリームから直接読み込むようにした

Modified Paths:
--------------
    trunk/bbs2chreader/chrome/content/bbs2chreader/server/skin.js

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/server/skin.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/server/skin.js	2007-07-24 13:00:46 UTC (rev 177)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/server/skin.js	2007-07-27 17:07:41 UTC (rev 178)
@@ -9,50 +9,51 @@
 			return;
 		}
 
-		if(channel.file && aServerHandler.requestHeaders["If-Modified-Since"]){
-			var lastModified = new Date(channel.file.lastModifiedTime).toUTCString();
-			var ifLastModified = aServerHandler.requestHeaders["If-Modified-Since"];
-			if(lastModified == ifLastModified){
-				aServerHandler.setResponseHeader("Last-Modified", lastModified);
-				aServerHandler.writeResponseHeader(304);
-				aServerHandler.close();
+
+		if(channel instanceof Components.interfaces.nsIFileChannel){
+				// File Not Found
+			if(!channel.file.exists()){
+				aServerHandler.sendErrorPage(404, aServerHandler.requestURL.spec);
 				return;
 			}
+
+			var lastModifiedString = new Date(channel.file.lastModifiedTime).toUTCString();
+			aServerHandler.setResponseHeader("Last-Modified", lastModifiedString);
+
+				// If-Modified-Since ‚ª‘¶Ý‚µƒtƒ@ƒCƒ‹‚ªXV‚³‚ê‚Ä‚¢‚È‚¯‚ê‚Î 304
+			if(aServerHandler.requestHeaders["If-Modified-Since"]){
+				var lastModified = parseInt(new Date(channel.file.lastModifiedTime).getTime() / 1000);
+				var ifLastModified = parseInt(new Date(aServerHandler.requestHeaders["If-Modified-Since"]).getTime() / 1000);
+				if(lastModified == ifLastModified){
+					aServerHandler.writeResponseHeader(304);
+					aServerHandler.close();
+					return;
+				}
+			}
+
+			aServerHandler.setResponseHeader("Content-Type", channel.contentType);
+			aServerHandler.writeResponseHeader(200);
+			var fileStream = Components.classes["@mozilla.org/network/file-input-stream;1"]
+								.createInstance(Components.interfaces.nsIFileInputStream);
+			fileStream.init(channel.file, 0x01, 0444, fileStream.CLOSE_ON_EOF);
+			aServerHandler._output.writeFrom(fileStream, channel.file.fileSize);
+			fileStream.close();
+			aServerHandler.close();
+			return;
 		}
 
-
 		var bInputStream = Components.classes["@mozilla.org/binaryinputstream;1"]
 					.createInstance(Components.interfaces.nsIBinaryInputStream);
+		var content = "";
 		try{
 			bInputStream.setInputStream(channel.open());
 			var content = bInputStream.readBytes(channel.contentLength);
+			bInputStream.close();
 		}catch(ex){
-			if(filePath.indexOf(".htm") != -1){
-					// —v‹‚µ‚½ƒtƒ@ƒCƒ‹‚ª html ‚̏ꍇA
-					// ‘¶Ý‚µ‚È‚­‚Ä‚à 404 ‚Å‚Í‚È‚­ 200 ‚Å‹ó‚̃eƒLƒXƒg‚ð•Ô‚·
-				aServerHandler.writeResponseHeader(200);
-				aServerHandler.write("");
-				aServerHandler.close();
-				return;
-			}else{
-				aServerHandler.sendErrorPage(404, aServerHandler.requestURL.spec);
-				return;
-			}
 			aServerHandler.sendErrorPage(404, aServerHandler.requestURL.spec);
 			return;
-
 		}
-
-		if(channel.contentType == "application/x-unknown-content-type"){
-			aServerHandler.sendErrorPage(404, aServerHandler.requestURL.spec);
-			return;
-		}
-
 		aServerHandler.setResponseHeader("Content-Type", channel.contentType);
-		if(channel.file){
-			var lastModified = new Date(channel.file.lastModifiedTime).toUTCString()
-			aServerHandler.setResponseHeader("Last-Modified", lastModified);
-		}
 		aServerHandler.writeResponseHeader(200);
 		aServerHandler.write(content);
 		aServerHandler.close();




bbs2ch-cvs メーリングリストの案内
Back to archive index