And example app to demonstrate the issue in chromium.
clone this sources and run npm install && npm start, then go to localhost:1337.
And example app to demonstrate the issue in chromium.
clone this sources and run npm install && npm start, then go to localhost:1337.
| <!DOCTYPE html> | |
| <html> | |
| <head lang="en"> | |
| <meta charset="UTF-8"> | |
| <title>test</title> | |
| <script src="http://code.jquery.com/jquery-2.1.1.js"></script> | |
| <script> | |
| $.ajax({ | |
| method: 'GET', | |
| url: '/login', | |
| headers: { 'authorization': 'Basic YmFkLWxvZ2luOnBhc3M=' }, | |
| success: function() { | |
| $('body').html('ok'); | |
| } | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| </body> | |
| </html> |
| { | |
| "scripts": { | |
| "start": "node server.js" | |
| }, | |
| "dependencies": { | |
| "express": "^4.4.4" | |
| } | |
| } |
| var express = require('express'), | |
| fs = require('fs'); | |
| var app = express(); | |
| function atob(str) { | |
| return new Buffer(str, 'base64').toString('binary'); | |
| } | |
| app.get('/login', function(req, res){ | |
| "use strict"; | |
| if(req.headers.authorization) { | |
| var auth = req.headers.authorization.split(' ').pop(); | |
| var login = atob(auth).split(':'); | |
| console.log((new Date()).toJSON() + ': ' + login[0]); | |
| if(login[0] === 'good-login') { | |
| res.writeHead(200, {'Content-Type': 'text/plain'}); | |
| res.end('Hello World\n'); | |
| return; | |
| } | |
| } | |
| res.setHeader('WWW-Authenticate', 'Basic realm="login-me"'); | |
| res.statusCode = 401; | |
| res.end(''); | |
| }); | |
| app.get('/', function(req, res) { | |
| "use strict"; | |
| fs.createReadStream('index.html', 'utf-8').pipe(res); | |
| }); | |
| var server = app.listen(1337, function() { | |
| console.log('Listening on port %d', server.address().port); | |
| }); |