| | 25 | urilib.AbsoluteURIError = function (message) { |
|---|
| | 26 | // Error thrown when relativeURI functions are called on an absoluteURI. |
|---|
| | 27 | this.message = message || "relativeURI functions cannot be called on an absoluteURI"; |
|---|
| | 28 | } |
|---|
| | 29 | urilib.AbsoluteURIError.prototype.toString = function () { |
|---|
| | 30 | return 'AbsoluteURIError: "' + this.message + '"'; |
|---|
| | 31 | } |
|---|
| | 32 | |
|---|
| | 33 | urilib.RelativeURIError = function (message) { |
|---|
| | 34 | // Error thrown when absoluteURI functions are called on a relativeURI. |
|---|
| | 35 | this.message = message || "absoluteURI functions cannot be called on a relativeURI"; |
|---|
| | 36 | } |
|---|
| | 37 | urilib.RelativeURIError.prototype.toString = function () { |
|---|
| | 38 | return 'RelativeURIError: "' + this.message + '"'; |
|---|
| | 39 | } |
|---|
| | 40 | |
|---|
| | 61 | urilib.URI.prototype.is_relative = function () { |
|---|
| | 62 | return (this.path.length > 0 && this.path.charAt(0) != '/'); |
|---|
| | 63 | } |
|---|
| | 64 | |
|---|
| | 65 | urilib.URI.prototype.net_path = function () { |
|---|
| | 66 | // Return the 'net_path' ("//" authority [ abs_path ]) of this URI. |
|---|
| | 67 | if (this.is_relative()) throw urilib.RelativeURIError(); |
|---|
| | 68 | return "//" + this.authority + this.path; |
|---|
| | 69 | }; |
|---|
| | 70 | |
|---|
| | 71 | urilib.URI.prototype.abs_path = function () { |
|---|
| | 72 | // Return the 'abs_path' ("/" path_segments) of this URI. |
|---|
| | 73 | if (this.is_relative()) throw urilib.RelativeURIError(); |
|---|
| | 74 | return this.path; |
|---|
| | 75 | }; |
|---|
| | 76 | |
|---|
| | 77 | urilib.URI.prototype.rel_path = function () { |
|---|
| | 78 | // Return the 'rel_path' (rel_segment [ abs_path ]) of this URI. |
|---|
| | 79 | if (!this.is_relative()) throw urilib.AbsoluteURIError(); |
|---|
| | 80 | return this.path; |
|---|
| | 81 | }; |
|---|
| | 82 | |
|---|
| | 83 | urilib.URI.prototype.hier_part = function (include_authority) { |
|---|
| | 84 | // Return the 'hier_part' ( net_path | abs_path ) [ "?" query ] of this URI. |
|---|
| | 85 | // |
|---|
| | 86 | // If 'include_authority' is false (the default), returns the |
|---|
| | 87 | // abs_path [+ query] by omitting the authority component. |
|---|
| | 88 | // Otherwise, returns the net_path [+ query] by including the |
|---|
| | 89 | // authority component. |
|---|
| | 90 | if (this.is_relative()) throw urilib.RelativeURIError(); |
|---|
| | 91 | var result = include_authority ? this.net_path() : this.path; |
|---|
| | 92 | if (this.query != '') result = result + "?" + this.query; |
|---|
| | 93 | return result; |
|---|
| | 94 | }; |
|---|
| | 95 | |
|---|
| | 96 | urilib.URI.prototype.server_relative = function () { |
|---|
| | 97 | // Return the 'server relative' ( abs_path | rel_path ) [ "?" query ] form of this URI. |
|---|
| | 98 | var result = this.path; |
|---|
| | 99 | if (this.query != '') result = result + "?" + this.query; |
|---|
| | 100 | return result; |
|---|
| | 101 | }; |
|---|