1 jls.loader.provide('jls.net.http.HttpResponseHeader'); 2 3 jls.loader.require('jls.net.http.HttpHeader'); 4 5 /* 6 Response = Status-Line 7 *( general-header 8 | response-header 9 | entity-header ) 10 CRLF 11 [ message-body ] 12 Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF 13 14 HTTP/1.0 404 Not Found 15 Content-Type: text/html; charset=UTF-8 16 X-Content-Type-Options: nosniff 17 Date: Sun, 19 Sep 2010 19:49:09 GMT 18 Server: sffe 19 Content-Length: 1360 20 X-XSS-Protection: 1; mode=block 21 */ 22 jls.net.http.HttpResponseHeader = jls.lang.Class.create(jls.net.http.HttpHeader, /** @lends jls.net.http.HttpResponseHeader.prototype */ 23 { 24 /** 25 * Creates an HTTP response header. 26 * 27 * @param {String} [version] The version. 28 * @param {Number} [statusCode] The status code. 29 * @param {String} [reasonPhrase] The reason phrase. 30 * @param {Object} [fields] The fields. 31 * @constructs 32 * @augments jls.net.http.HttpHeader 33 * @class This class represents an HTTP response header. 34 */ 35 initialize : function($super, version, statusCode, reasonPhrase, fields) { 36 this._version = jls.net.http.HttpHeader.VERSION_PREFIX + jls.net.http.HttpHeader.VERSION_1_0; 37 this._statusCode = jls.net.http.HttpHeader.HTTP_OK; 38 this._reasonPhrase = 'n/a'; 39 if (statusCode) { 40 this.setStatusCode(statusCode); 41 } 42 if (reasonPhrase) { 43 this.setReasonPhrase(reasonPhrase); 44 } 45 if (version) { 46 this.setVersion(version); 47 } 48 $super(null, fields); 49 }, 50 /** 51 * Returns the version. 52 * 53 * @returns {String} The version. 54 */ 55 getVersion : function() { 56 return this._version; 57 }, 58 /** 59 * Sets the version. 60 * 61 * @param {String} version The version. 62 */ 63 setVersion : function(version) { 64 this._version = version; 65 return this; 66 }, 67 /** 68 * Returns the status code. 69 * 70 * @returns {String} The status code. 71 */ 72 getStatusCode : function() { 73 return this._statusCode; 74 }, 75 /** 76 * Sets the status code. 77 * 78 * @param {String} version The status code. 79 */ 80 setStatusCode : function(statusCode) { 81 this._statusCode = statusCode; 82 return this; 83 }, 84 /** 85 * Returns the reason phrase. 86 * 87 * @returns {String} The reason phrase. 88 */ 89 getReasonPhrase : function() { 90 return this._reasonPhrase; 91 }, 92 /** 93 * Sets the reason phrase. 94 * 95 * @param {String} version The reason phrase. 96 */ 97 setReasonPhrase : function(reasonPhrase) { 98 this._reasonPhrase = reasonPhrase; 99 return this; 100 }, 101 getStartLine : function() { 102 return this.getVersion() + ' ' + this.getStatusCode() + ' ' + this.getReasonPhrase(); 103 }, 104 setStartLine : function(line) { 105 var items = line.split(' '); 106 if (items.length < 3) { 107 throw new jls.lang.IllegalArgumentException(); 108 } 109 this.setVersion(items[0]); 110 this.setStatusCode(items[1]); 111 this.setReasonPhrase(items[2]); // TODO the reason phrase can contain spaces 112 return this; 113 } 114 }); 115