Guest User

Untitled

a guest
Jan 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. app.use('/api', function(req, res) {
  2. var url = rewriteUrl(req.url);
  3.  
  4. var newReq = request(url, function(error) {
  5. if (error) {
  6. logError(error);
  7. }
  8. });
  9.  
  10. req.pipe(newReq).pipe(res);
  11. });
  12.  
  13. app.use('/api', function(req, res) {
  14. var url = rewriteUrl(req.url);
  15.  
  16. var newReq = http.request(url, function(newRes) {
  17. var headers = newRes.headers;
  18.  
  19. // modify `headers` here ...
  20.  
  21. res.writeHead(newRes.statusCode, headers);
  22. newRes.pipe(res);
  23. }).on('error', function(err) {
  24. res.statusCode = 500;
  25. res.end();
  26. });
  27.  
  28. req.pipe(newReq);
  29. });
  30.  
  31. req.pipe(newReq).pipe(res);
  32.  
  33. req.pipe(newReq).on('response', function(res) {
  34. delete res.headers['user-agent'];
  35. // ...
  36. }).pipe(res);
  37.  
  38. const req = request.get(url);
  39. req.pipefilter = function(response, dest) {
  40. // remove headers
  41. for(const h in response.headers) {
  42. dest.removeHeader(h);
  43. }
  44. // or modify
  45. dest.setHeader('Content-Type', 'text/html')
  46. }
  47. req.pipe(resp)
Add Comment
Please, Sign In to add comment