Created
April 27, 2013 12:19
-
-
Save shiedman/5472925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net=require('net'), | |
express = require('express'), | |
app = express(); | |
app.get('*', function(req,res){ | |
var filename='中文名.js'; | |
//filename=new Buffer(filename).toString('binary'); | |
console.log('before download: %s',unicode(filename)); | |
res.download(__filename,filename); | |
}); | |
app.listen(8080, function(){ | |
console.log("listening on port %d", this.address().port); | |
var client=net.connect(8080,function(){ | |
client.write('GET / HTTP/1.1\r\nHost:localhost\r\n\r\n'); | |
}); | |
client.once('data',function(chunk){ | |
var s=chunk.toString('binary'), | |
i=s.indexOf('"'), | |
j=s.indexOf('"',i+1); | |
console.log('after download: %s',unicode(s.substring(i+1,j))); | |
process.exit(0); | |
}); | |
}); | |
function unicode(s){ | |
var f=''; | |
[].forEach.call(s,function(e){ | |
f+='\\x'+e.charCodeAt().toString(16)+'\t'; | |
}) | |
return f | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment