Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • N node-http-proxy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 482
    • Issues 482
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 102
    • Merge requests 102
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • http ... PARTY!
  • node-http-proxy
  • Merge requests
  • !1318

feat: Add `mergeCookies` option

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/RidgeA/feat/merge_set-cookie_header into master Jan 14, 2019
  • Overview 7
  • Commits 1
  • Pipelines 0
  • Changes 5

Created by: RidgeA

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.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/RidgeA/feat/merge_set-cookie_header