proxy.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var spdy = require('spdy')
  2. var fs = require('fs')
  3. var http = require('http')
  4. var options = {
  5. key: fs.readFileSync(__dirname + '/../certs/server.key'),
  6. cert: fs.readFileSync(__dirname + '/../certs/server.crt'),
  7. ca: fs.readFileSync(__dirname + '/../certs/ca.crt'),
  8. // **optional** SPDY-specific options
  9. windowSize: 1024 * 1024, // Server's window size
  10. // **optional** if true - server will send 3.1 frames on 3.0 *plain* spdy
  11. autoSpdy31: false
  12. }
  13. var server = spdy.createServer(options, function(req, res) {
  14. var options = {
  15. hostname: req.headers.host,
  16. port: 80,
  17. path: req.url,
  18. method: 'GET'
  19. }
  20. var proxyReq = http.request(options, function(proxyRes) {
  21. var headers = {'Server':'Neocities'}
  22. if(proxyRes.headers['content-length'])
  23. headers['Content-Length'] = proxyRes.headers['content-length']
  24. if(proxyRes.headers['content-type'])
  25. headers['Content-Type'] = proxyRes.headers['content-type']
  26. if(proxyRes.headers['etag'])
  27. headers['ETag'] = proxyRes.headers['etag']
  28. if(proxyRes.headers['last-modified'])
  29. headers['Last-Modified'] = proxyRes.headers['last-modified']
  30. res.writeHead(proxyRes.statusCode, headers)
  31. // TODO: Chunks pushed to cache too
  32. proxyRes.on('data', function (chunk) {
  33. res.write(chunk)
  34. })
  35. })
  36. proxyReq.end()
  37. //req.pipe(proxy)
  38. })
  39. server.listen(443)