Skip to content

Commit

Permalink
Modified resources and xhr to better work with SSL (Ken Sternberg)
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Jul 29, 2011
1 parent 06d7a09 commit 0ff156d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@ leaning on its http module (Ryan Petrello)


Added a basic infection/installation section to documentation (terryp) Added a basic infection/installation section to documentation (terryp)


Modified resources and xhr to better work with SSL (Ken Sternberg)



### Version 0.9.5 2011-04-11 ### Version 0.9.5 2011-04-11


Expand Down
22 changes: 14 additions & 8 deletions src/zombie/resources.coffee
Expand Up @@ -10,6 +10,7 @@


inspect = require("util").inspect inspect = require("util").inspect
HTTP = require("http") HTTP = require("http")
HTTPS = require("https")
FS = require("fs") FS = require("fs")
QS = require("querystring") QS = require("querystring")
URL = require("url") URL = require("url")
Expand Down Expand Up @@ -139,11 +140,9 @@ class Resources extends Array
makeRequest = (method, url, data, headers, resource, callback)=> makeRequest = (method, url, data, headers, resource, callback)=>
url = URL.parse(url) url = URL.parse(url)


#
# If the request is for a file:// descriptor, just open directly from the # If the request is for a file:// descriptor, just open directly from the
# file system rather than getting node's http (which handles file:// # file system rather than getting node's http (which handles file://
# poorly) involved. # poorly) involved.
#
if url.protocol == 'file:' if url.protocol == 'file:'
FS.readFile url.pathname, (err, data) => FS.readFile url.pathname, (err, data) =>
# Fallback with error -> callback # Fallback with error -> callback
Expand Down Expand Up @@ -225,8 +224,6 @@ class Resources extends Array
# string. # string.
secure = url.protocol == "https:" secure = url.protocol == "https:"
url.port ||= if secure then 443 else 80 url.port ||= if secure then 443 else 80
client = HTTP.createClient(url.port, url.hostname, secure)
request = client.request(method, "#{url.pathname}#{url.search || ""}", headers)


# First request has not resource, so create it and add to # First request has not resource, so create it and add to
# Resources. After redirect, we have a resource we're using. # Resources. After redirect, we have a resource we're using.
Expand All @@ -235,9 +232,13 @@ class Resources extends Array
this.push resource this.push resource
window.browser.log -> "#{method} #{URL.format(url)}" window.browser.log -> "#{method} #{URL.format(url)}"


# Connection error wired directly to callback. request =
client.on "error", callback host: url.hostname
request.on "response", (response)=> port: url.port
path: "#{url.pathname}#{url.search || ""}"
method: method
headers: headers
response_handler = (response)=>
response.setEncoding "utf8" response.setEncoding "utf8"
body = "" body = ""
response.on "data", (chunk)-> body += chunk response.on "data", (chunk)-> body += chunk
Expand Down Expand Up @@ -271,7 +272,12 @@ class Resources extends Array
error.response = resource.response error.response = resource.response
resource.error = error resource.error = error
callback error callback error
request.end body, "utf8"
client = (if secure then HTTPS else HTTP).request(request, response_handler)
# Connection error wired directly to callback.
client.on "error", callback
client.write body
client.end()


typeOf = (object)-> typeOf = (object)->
return Object.prototype.toString.call(object) return Object.prototype.toString.call(object)
Expand Down
2 changes: 1 addition & 1 deletion src/zombie/xhr.coffee
Expand Up @@ -46,7 +46,7 @@ XMLHttpRequest = (window)->
url.host = if url.port then "#{url.hostname}:#{url.port}" else url.hostname url.host = if url.port then "#{url.hostname}:#{url.port}" else url.hostname
url.hash = null url.hash = null
throw new core.DOMException(core.SECURITY_ERR, "Cannot make request to different domain") unless url.host == window.location.host throw new core.DOMException(core.SECURITY_ERR, "Cannot make request to different domain") unless url.host == window.location.host
throw new core.DOMException(core.NOT_SUPPORTED_ERR, "Only HTTP protocol supported") unless url.protocol == "http:" throw new core.DOMException(core.NOT_SUPPORTED_ERR, "Only HTTP/S protocol supported") unless url.protocol in ["http:", "https:"]
[user, password] = url.auth.split(":") if url.auth [user, password] = url.auth.split(":") if url.auth


# Aborting open request. # Aborting open request.
Expand Down

0 comments on commit 0ff156d

Please sign in to comment.