Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c8b44379c | |||
| c36da3bade |
@@ -11,7 +11,12 @@ http.request = function (opts, cb) {
|
||||
else
|
||||
opts = extend(opts)
|
||||
|
||||
var protocol = opts.protocol || ''
|
||||
// Normally, the page is loaded from http or https, so not specifying a protocol
|
||||
// will result in a (valid) protocol-relative url. However, this won't work if
|
||||
// the protocol is something else, like 'file:'
|
||||
var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : ''
|
||||
|
||||
var protocol = opts.protocol || defaultProtocol
|
||||
var host = opts.hostname || opts.host
|
||||
var port = opts.port
|
||||
var path = opts.path || '/'
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "stream-http",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.5",
|
||||
"description": "Streaming http in the browser",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -64,6 +64,25 @@ test('Test alt protocol', function(t) {
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Test page with \'file:\' protocol', function (t) {
|
||||
var params = {
|
||||
hostname: 'localhost',
|
||||
port: 3000,
|
||||
path: '/bar'
|
||||
}
|
||||
|
||||
var fileLocation = 'file:///home/me/stuff/index.html'
|
||||
|
||||
var normalLocation = global.location
|
||||
global.location = url.parse(fileLocation) // Temporarily change the location
|
||||
var request = http.get(params, noop)
|
||||
global.location = normalLocation // Reset the location
|
||||
|
||||
var resolved = url.resolve(fileLocation, request._opts.url)
|
||||
t.equal(resolved, 'http://localhost:3000/bar', 'Url should be correct')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Test string as parameters', function(t) {
|
||||
var testUrl = '/api/foo'
|
||||
var request = http.get(testUrl, noop)
|
||||
|
||||
Reference in New Issue
Block a user