1 jls.loader.provide('jls.net.http.HttpRequestHeader');
  2 
  3 jls.loader.require('jls.net.http.HttpHeader');
  4 
  5 /*
  6 Request      = Request-Line
  7                            *( general-header
  8                             | request-header
  9                             | entity-header )
 10                            CRLF
 11                            [ message-body ]
 12 Request-Line = Method SP Request-URI SP HTTP-Version CRLF
 13 */
 14 jls.net.http.HttpRequestHeader = jls.lang.Class.create(jls.net.http.HttpHeader, /** @lends jls.net.http.HttpRequestHeader.prototype */
 15 {
 16     /**
 17      * Creates an HTTP request header.
 18      *
 19      * @param {String} [method] The method.
 20      * @param {String} [uri] The uri.
 21      * @param {String} [version] The version.
 22      * @param {Object} [fields] The fields.
 23      * @constructs
 24 	 * @augments jls.net.http.HttpHeader
 25 	 * @class This class represents an HTTP request header.
 26      */
 27     initialize : function($super, method, uri, version, fields) {
 28         this._method = jls.net.http.HttpHeader.METHOD_GET;
 29         this._uri = '/';
 30         this._version = jls.net.http.HttpHeader.VERSION_PREFIX + jls.net.http.HttpHeader.VERSION_1_0;
 31         if (method) {
 32             this.setMethod(method);
 33         }
 34         if (uri) {
 35             this.setUri(uri);
 36         }
 37         if (version) {
 38             this.setVersion(version);
 39         }
 40         $super(null, fields);
 41     },
 42     /**
 43      * Returns the method.
 44      * 
 45      * @returns {String} The version.
 46      */
 47     getMethod : function() {
 48         return this._method;
 49     },
 50     /**
 51      * Sets the method.
 52      * 
 53      * @param {String} version The version.
 54      */
 55     setMethod : function(method) {
 56         this._method = method;
 57         return this;
 58     },
 59     /**
 60      * Returns the URI.
 61      * 
 62      * @returns {String} The URI.
 63      */
 64     getUri : function() {
 65         return this._uri;
 66     },
 67     /**
 68      * Sets the URI.
 69      * 
 70      * @param {String} version The URI.
 71      */
 72     setUri : function(uri) {
 73         jls.logger.trace('setUri("' + uri + '")');
 74         this._uri = uri;
 75         return this;
 76     },
 77     /**
 78      * Returns the version.
 79      * 
 80      * @returns {String} The version.
 81      */
 82     getVersion : function() {
 83         return this._version;
 84     },
 85     /**
 86      * Sets the version.
 87      * 
 88      * @param {String} version The version.
 89      */
 90     setVersion : function(version) {
 91         this._version = version;
 92         return this;
 93     },
 94     getStartLine : function() {
 95         return this.getMethod() + ' ' + this.getUri() + ' ' + this.getVersion();
 96     },
 97     setStartLine : function(line) {
 98         jls.logger.trace('setStartLine("' + line + '")');
 99         var items = line.split(' ');
100         if (items.length != 3) {
101             throw new jls.lang.IllegalArgumentException();
102         }
103         this.setMethod(items[0]);
104         this.setUri(items[1]);
105         this.setVersion(items[2]);
106         return this;
107     }
108 });
109