[Bbs2ch-cvs 216] [198] リクエストヘッダを nsIUnicharLineInputStream で読み込むようにした

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 8月 13日 (月) 00:53:38 JST


Revision: 198
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=198
Author:   flyson
Date:     2007-08-13 00:53:38 +0900 (Mon, 13 Aug 2007)

Log Message:
-----------
リクエストヘッダを nsIUnicharLineInputStream で読み込むようにした

Modified Paths:
--------------
    trunk/bbs2chreader/components/b2rServer.js

Modified: trunk/bbs2chreader/components/b2rServer.js
===================================================================
--- trunk/bbs2chreader/components/b2rServer.js	2007-08-11 10:55:24 UTC (rev 197)
+++ trunk/bbs2chreader/components/b2rServer.js	2007-08-12 15:53:38 UTC (rev 198)
@@ -321,12 +321,8 @@
 		this._transport = aTransport;
 		this._currentThread = aServer.currentThread;
 
-		this._input = this._transport.openInputStream(1, 0, 0)
-				.QueryInterface(Components.interfaces.nsIAsyncInputStream);
+		this._input = this._transport.openInputStream(1, 0, 0);
 		this._output = this._transport.openOutputStream(1, 1024*16, 64);
-//		this._output = Components.classes["@mozilla.org/network/buffered-output-stream;1"]
-//				.createInstance(Components.interfaces.nsIBufferedOutputStream);
-//		this._output.init(this._transport.openOutputStream(1, 0, 0), 64*1024);
 
 		this._method = "";
 		this._httpVersion = "";
@@ -335,31 +331,44 @@
 		this._requestURL = null;
 		this._getData = new Array();
 
-		this._requestData = "";
-		this._input.asyncWait(this, 0, 0, this._server._eventQueue);
+		this._parseRequestData();
+		this._responseHeaders["Host"] = this.requestURL.host;
+		this._responseHeaders["Date"] = new Date().toUTCString();
+		this._responseHeaders["Content-Type"] = "text/plain; charset=UTF-8";
+		this._responseHeaders["Connection"] = "close";
+		this._startScript();
 	},
 
 
 
 	_parseRequestData: function(){
-		var requestData = this._requestData;
+		var inputStram = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
+				.createInstance(Components.interfaces.nsIConverterInputStream)
+				.QueryInterface(Components.interfaces.nsIUnicharLineInputStream);
+		inputStram.init(this._input, "ISO-8859-1", 1024, 0xFFFD);
+		var line = {};
 
-		var uri = "";
-		var headerLines = requestData.split("\r\n");
-		var requestLine = headerLines.shift();
-		if(requestLine.match(/(.+) (.+) (.+)/)){
-			this._method = RegExp.$1;
-			uri = RegExp.$2;
-			this._httpVersion = RegExp.$3;
+			// HTTP ƒwƒbƒ_
+		while (inputStram.readLine(line) && line.value.length == 0){
+			// æ“ª‚̋󔒍s‚𖳎‹‚·‚é
 		}
+		var herderLine = line.value;
 
-		for(var i=0; i<headerLines.length; i++){
-			var headerLine = headerLines[i];
-			if(headerLine.match(/([^: ]+)[: ]*(.+)/i)){
+			// ƒŠƒNƒGƒXƒgƒwƒbƒ_•”•ª
+		while (inputStram.readLine(line)){
+			if(line.value == "") break;
+			if(line.value.match(/([^: ]+)[: ]*(.+)/i)){
 				this._requestHeaders[RegExp.$1] = RegExp.$2;
 			}
 		}
 
+		var uri = "";
+		if(herderLine.match(/(.+) (.+) (.+)/)){
+			this._method = RegExp.$1;
+			uri = RegExp.$2;
+			this._httpVersion = RegExp.$3;
+		}
+
 		var ioService = Components.classes["@mozilla.org/network/io-service;1"]
 				.getService(Components.interfaces.nsIIOService);
 		try{
@@ -378,34 +387,8 @@
 		}
 	},
 
-	onInputStreamReady: function(aStream){
-		var bStream = Components.classes["@mozilla.org/binaryinputstream;1"]
-				.createInstance(Components.interfaces.nsIBinaryInputStream);
-		bStream.setInputStream(aStream);
 
-		var available = bStream.available();
-		if(available > 0){
-			this._requestData += bStream.readBytes(available);
-			if(this._requestData.indexOf("\r\n\r\n") != -1){
-				this._requestData = this._requestData.split("\r\n\r\n")[0];
-				this._startScript();
-				return;
-			}
-		}else{
-			dump(this._requestData +"\n");
-			this.close();
-		}
-		this._input.asyncWait(this, 0, 0, this._server._eventQueue);
-	},
-
 	_startScript: function(){
-		this._parseRequestData();
-
-		this._responseHeaders["Host"] = this.requestURL.host;
-		this._responseHeaders["Date"] = new Date().toUTCString();
-		this._responseHeaders["Content-Type"] = "text/plain; charset=UTF-8";
-		this._responseHeaders["Connection"] = "close";
-
 		if(this.method != "GET"){
 			this.sendErrorPage(501, this.method + " Is Not Implemented");
 			return;




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