Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add `mergeCookies` option #1318

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
1 participant
@RidgeA
Copy link

RidgeA commented Jan 14, 2019

mergeCookie options allow to merge set-cookie header form passed request object and from a target response

Test added.
Documentation updated.

Use Case:
In the project, I'm working on currently, we are using Express-Gateway (https://github.com/ExpressGateway/express-gateway) as a single entry point for a set of microservices.
Express-Gateway uses http-proxy when proxeing requests to a destination service.
In the gateway we have to setup a cookie with CSRF token.
But some endpoints of our microservices setups it's own cookies and in this case all cookies, that has been setuped in gateway wipes out by cookies from a microservice response.

Raw example:

"use strict";

const http = require("http");
const httpProxy = require("http-proxy");
const proxy = httpProxy.createProxyServer({});

const gateway = http.createServer((req, res) => {
  res.setHeader('set-cookie', ["gateway=true; Path=/"]);
  proxy.web(req, res, {target: "http://localhost:3002"});
});

gateway.listen(3003);

const backend = http.createServer((req, res) => {
  res.setHeader("set-cookie", ["backend=true; Path=/", "another_backend_cookie=true; Path=/"]);
  res.end("OK");
});

backend.listen(3002);

Curl:

$ curl -v http://localhost:3003
* Rebuilt URL to: http://localhost:3003/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3003 (#0)
> GET / HTTP/1.1
> Host: localhost:3003
> User-Agent: curl/7.61.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< set-cookie: backend=true; Path=/
< set-cookie: another_backend_cookie=true; Path=/
< date: Mon, 14 Jan 2019 12:24:27 GMT
< connection: close
< content-length: 2
< 
* Closing connection 0
OK

By this pull-request I want to add one more option that will instruct proxy-server to merge set-cookie header instead of overwriting it.
Existing behaviour remains the same.

feat: Add `mergeCookies` option
`mergeCookie` options allows to merge `set-cookie` header form passed request object and from target
@RidgeA

This comment has been minimized.

Copy link
Author

RidgeA commented Feb 12, 2019

Hi!
Is there any chance that it will be merged?
Do I need to change something ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.