svnno****@sourc*****
svnno****@sourc*****
2007年 12月 29日 (土) 01:21:18 JST
Revision: 294 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=294 Author: flyson Date: 2007-12-29 01:21:17 +0900 (Sat, 29 Dec 2007) Log Message: ----------- レスポンスコードの取得を別オブジェクト化 Modified Paths: -------------- trunk/bbs2chreader/components/b2rServer.js -------------- next part -------------- Modified: trunk/bbs2chreader/components/b2rServer.js =================================================================== --- trunk/bbs2chreader/components/b2rServer.js 2007-12-20 11:39:35 UTC (rev 293) +++ trunk/bbs2chreader/components/b2rServer.js 2007-12-28 16:21:17 UTC (rev 294) @@ -52,6 +52,84 @@ const B2R_SERVER_CNAME = "b2rServer js component"; + + +var StatusCode = { + + getStatusCode: function(aCode){ + if(!this._statusCode){ + this._statusCode = new Array(); + + this._statusCode["s100"] = "100 Continue"; + this._statusCode["s101"] = "101 Switching Protocols"; + this._statusCode["s102"] = "102 Processing"; + + this._statusCode["s200"] = "200 OK"; + this._statusCode["s201"] = "201 Created"; + this._statusCode["s202"] = "202 Accepted"; + this._statusCode["s203"] = "203 Non-Authoritative Information"; + this._statusCode["s204"] = "204 No Content"; + this._statusCode["s205"] = "205 Reset Content"; + this._statusCode["s206"] = "206 Partial Content"; + this._statusCode["s207"] = "207 Multi-Status"; + this._statusCode["s226"] = "226 IM Used"; + + this._statusCode["s300"] = "300 Multiple Choices"; + this._statusCode["s301"] = "301 Moved Permanently"; + this._statusCode["s302"] = "302 Found"; + this._statusCode["s303"] = "303 See Other"; + this._statusCode["s304"] = "304 Not Modified"; + this._statusCode["s305"] = "305 Use Proxy"; + this._statusCode["s306"] = "306 (Unused)"; + this._statusCode["s307"] = "307 Temporary Redirect"; + this._statusCode["s400"] = "400 Bad Request"; + this._statusCode["s401"] = "401 Unauthorized"; + this._statusCode["s402"] = "402 Payment Required"; + this._statusCode["s403"] = "403 Forbidden"; + this._statusCode["s404"] = "404 Not Found"; + this._statusCode["s405"] = "405 Method Not Allowed"; + this._statusCode["s406"] = "406 Not Acceptable"; + this._statusCode["s407"] = "407 Proxy Authentication Required"; + this._statusCode["s408"] = "408 Request Timeout"; + this._statusCode["s403"] = "409 Conflict"; + this._statusCode["s410"] = "410 Gone"; + this._statusCode["s411"] = "411 Length Required"; + this._statusCode["s412"] = "412 Precondition Failed"; + this._statusCode["s413"] = "413 Request Entity Too Large"; + this._statusCode["s414"] = "414 Request-URI Too Long"; + this._statusCode["s415"] = "415 Unsupported Media Type"; + this._statusCode["s416"] = "416 Requested Range Not Satisfiable"; + this._statusCode["s417"] = "417 Expectation Failed"; + this._statusCode["s418"] = "418 I'm a teapot"; + this._statusCode["s422"] = "422 Unprocessable Entity"; + this._statusCode["s423"] = "423 Locked"; + this._statusCode["s424"] = "424 Failed Dependency"; + this._statusCode["s426"] = "426 Upgrade Required"; + + this._statusCode["s500"] = "500 Internal Server Error"; + this._statusCode["s501"] = "501 Not Implemented"; + this._statusCode["s502"] = "502 Bad Gateway"; + this._statusCode["s503"] = "503 Service Unavailable"; + this._statusCode["s504"] = "504 Gateway Timeout"; + this._statusCode["s505"] = "505 HTTP Version Not Supported"; + this._statusCode["s506"] = "506 Variant Also Negotiates"; + this._statusCode["s507"] = "507 Insufficient Storage"; + this._statusCode["s510"] = "510 Not Extended"; + } + + if(this._statusCode["s" + aCode]){ + return this._statusCode["s" + aCode]; + } + + // throw "Not Difined Response Code"; + return "200 OK"; + } + +}; + + + + // ********** ********* b2rServer ********** ********** function b2rServer(){ @@ -445,32 +523,7 @@ }, writeResponseHeader: function(aStatusCode){ - var status = "200 OK"; - switch(aStatusCode){ - case 200: - status = "200 OK"; - break; - case 304: - status = "304 Not Modified"; - break; - case 400: - status = "400 Bad Request"; - break; - case 402: - status = "402 Forbidden"; - break; - case 404: - status = "404 Not Found"; - break; - case 500: - status = "500 Internal Server Error"; - break; - case 501: - status = "501 Not Implemented"; - break; - } - - this.write("HTTP/1.0 " + status + "\r\n"); + this.write("HTTP/1.1 " + StatusCode.getStatusCode(aStatusCode) + "\r\n"); for(var i in this._responseHeaders){ this.write(i + ": " + this._responseHeaders[i] + "\r\n"); } @@ -494,24 +547,7 @@ this.setResponseHeader("Content-Type", "text/html; charset=UTF-8"); this.writeResponseHeader(aStatusCode); - var status = "200 OK"; - switch(aStatusCode){ - case 200: - status = "200 OK"; - break; - case 400: - status = "400 Bad Request"; - break; - case 404: - status = "404 Not Found"; - break; - case 500: - status = "500 Internal Server Error"; - break; - case 501: - status = "501 Not Implemented"; - break; - } + var status = StatusCode.getStatusCode(aStatusCode); var html = <html> <head><title>{status} [bbs2chserver]</title></head>