Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. set-cookie: MYSPECIALCOOKIE=679b6291-d1cc-47be; Path=/app; HttpOnly
  2.  
  3. set-cookie: MYSPECIALCOOKIE=679b6291-d1cc-47be; Path=/; HttpOnly; Secure
  4.  
  5. httpProxy = require('http-proxy');
  6.  
  7. httpProxy.createServer(function (req, res, proxy) {
  8.  
  9. res.oldWriteHead = res.writeHead;
  10. res.writeHead = function(statusCode, headers) {
  11. /* add logic to change headers here */
  12. var contentType = res.getHeader('content-type');
  13. res.setHeader('content-type', 'text/plain');
  14.  
  15. // old way: might not work now
  16. // as headers param is not always provided
  17. // https://github.com/nodejitsu/node-http-proxy/pull/260/files
  18. // headers['foo'] = 'bar';
  19.  
  20. res.oldWriteHead(statusCode, headers);
  21. }
  22.  
  23. proxy.proxyRequest(req, res, {
  24. host: 'localhost',
  25. port: 3000
  26. });
  27. }).listen(8000);
  28.  
  29. response.setHeader("Set-Cookie", ["type=ninja", "language=javascript"]);
  30.  
  31. // curl -k https://localhost:8000/
  32. var https = require('https');
  33. var fs = require('fs');
  34.  
  35. var options = {
  36. key: fs.readFileSync('path_to_key.pem'),
  37. cert: fs.readFileSync('path_to_cert.pem')
  38. };
  39.  
  40. https.createServer(options, function (req, res) {
  41. var body = "hello"
  42. res.writeHead(200,{
  43. 'Content-Length': body.length,
  44. 'Content-Type': 'text/plain',
  45. 'set-cookie': "MYSPECIALCOOKIE=679b6291-d1cc-47be; Path=/; HttpOnly; Secure"
  46. });
  47. res.end("hello worldn");
  48. }).listen(8000);
  49.  
  50. var httpProxy = require('http-proxy');
  51.  
  52. var server = httpProxy.createServer(function (req, res, proxy) {
  53. var buffer = httpProxy.buffer(req);
  54. req.headers['x-host'] = process.env.PROXY_URI;
  55. proxy.proxyRequest(req, res, {
  56. host: '127.0.0.1',
  57. port: 9000,
  58. });
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement