Rev 981 | Rev 984 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 981 | Rev 983 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | } |
4 | } |
| 5 | 5 | ||
| 6 | HTTP.prototype.mySocket = null; |
6 | HTTP.prototype.mySocket = null; |
| 7 | HTTP.prototype.myUserCallback = null; |
7 | HTTP.prototype.myUserCallback = null; |
| 8 | HTTP.prototype.myBuffer = null; |
8 | HTTP.prototype.myBuffer = null; |
| - | 9 | HTTP.prototype.myRequest = null; |
|
| 9 | 10 | ||
| 10 | HTTP.prototype.request = function(callback, url) |
11 | HTTP.prototype.request = function(callback, url) |
| 11 | { |
12 | { |
| 12 | this.myUserCallback = callback; |
13 | this.myUserCallback = callback; |
| 13 | 14 | ||
| Line 27... | Line 28... | ||
| 27 | this.myBuffer = ""; |
28 | this.myBuffer = ""; |
| 28 | 29 | ||
| 29 | this.mySocket = new Socket(function(event, data) { self.socketCallback(event, data); }, urlData['hostname'], urlData['port'], 0); |
30 | this.mySocket = new Socket(function(event, data) { self.socketCallback(event, data); }, urlData['hostname'], urlData['port'], 0); |
| 30 | this.mySocket.start(); |
31 | this.mySocket.start(); |
| 31 | 32 | ||
| 32 |
|
33 | this.myRequest = "GET " + urlData['path'] + " HTTP/1.1\r\n"; |
| 33 |
|
34 | this.myRequest += "Host: " + urlData['hostname'] + ":" + urlData['port'] + "\r\n"; |
| 34 |
|
35 | this.myRequest += "Connection: close\r\n"; |
| 35 |
|
36 | this.myRequest += "\r\n"; |
| 36 | - | ||
| 37 | this.mySocket.send(request); |
- | |
| 38 | } |
37 | } |
| 39 | 38 | ||
| 40 | HTTP.prototype.parseUrl = function(url) |
39 | HTTP.prototype.parseUrl = function(url) |
| 41 | { |
40 | { |
| 42 | var result = new Array(); |
41 | var result = new Array(); |
| 43 | result['port'] = 80; |
42 | result['port'] = 80; |
| 44 | result['path'] = "/"; |
43 | result['path'] = "/"; |
| 45 | 44 | ||
| 46 | var firstSlash = url.indexOf('/'); |
45 | var firstSlash = url.indexOf('/'); |
| 47 | 46 | ||
| 48 | if (firstSlash == -1) |
47 | if (firstSlash == -1) |
| 49 | { |
48 | { |
| 50 | result['hostname'] = url; |
49 | result['hostname'] = url; |
| 51 | } |
50 | } |
| 52 | else |
51 | else |
| 53 | { |
52 | { |
| 54 | result['hostname'] = url.substr(0, firstSlash); |
53 | result['hostname'] = url.substr(0, firstSlash); |
| 55 | result['path'] = url.substr(firstSlash); |
54 | result['path'] = url.substr(firstSlash); |
| 56 | } |
55 | } |
| 57 | 56 | ||
| 58 | var firstColon = result['hostname'].indexOf(':'); |
57 | var firstColon = result['hostname'].indexOf(':'); |
| 59 | 58 | ||
| 60 | if (firstColon != -1) |
59 | if (firstColon != -1) |
| 61 | { |
60 | { |
| 62 | result['port'] = result['hostname'].substr(firstColon+1); |
61 | result['port'] = result['hostname'].substr(firstColon+1); |
| 63 | result['hostname'] = result['hostname'].substr(0, firstColon); |
62 | result['hostname'] = result['hostname'].substr(0, firstColon); |
| 64 | } |
63 | } |
| 65 | 64 | ||
| 66 | return result; |
65 | return result; |
| 67 | } |
66 | } |
| 68 | 67 | ||
| 69 | HTTP.prototype.socketCallback = function(event, data) |
68 | HTTP.prototype.socketCallback = function(event, data) |
| 70 | { |
69 | { |
| 71 | switch (event) |
70 | switch (event) |
| 72 | { |
71 | { |
| - | 72 | case "EVENT_CONNECTED": |
|
| - | 73 | this.mySocket.send(this.myRequest); |
|
| - | 74 | break; |
|
| - | 75 | ||
| 73 | case "EVENT_DATA": |
76 | case "EVENT_DATA": |
| 74 | this.myBuffer += unescape(data); |
77 | this.myBuffer += unescape(data); |
| 75 | break; |
78 | break; |
| 76 | 79 | ||
| - | 80 | case "EVENT_RESET": |
|
| 77 | case "EVENT_CLOSED": |
81 | case "EVENT_CLOSED": |
| 78 | case "EVENT_DIED": |
82 | case "EVENT_DIED": |
| 79 | this.mySocket.stop(); |
83 | this.mySocket.stop(); |
| 80 | this.processBuffer(); |
84 | this.processBuffer(); |
| 81 | break; |
85 | break; |