New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apollo-server-plugin-http-headers

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-server-plugin-http-headers - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

12

package.json
{
"name": "apollo-server-plugin-http-headers",
"version": "0.1.2",
"version": "0.1.3",
"description": "Allows you to set HTTP Headers and Cookies easily in your apollo server resolvers.",

@@ -14,3 +14,11 @@ "main": "src/index.js",

"homepage": "https://github.com/b2a3e8/apollo-server-plugin-http-headers",
"keywords": ["apollo", "apollo-server", "plugin", "header", "cookie", "graphql", "lambda"],
"keywords": [
"apollo",
"apollo-server",
"plugin",
"header",
"cookie",
"graphql",
"lambda"
],
"license": "MIT",

@@ -17,0 +25,0 @@ "dependencies": {

@@ -137,1 +137,8 @@ # apollo-server-plugin-http-headers

secure | Specifies the boolean value for the [`Secure` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.5).By default, the `Secure` attribute is not set.
## Limitations
### Only one cookie can be set per request
There is at the moment no possility to set multiple cookies because apollo server does not support that. Find details and workaround inspiration [here](https://github.com/apollographql/apollo-server/issues/3040).
If you add multiple items to setCookie I'll throw an exception at your face (-;

13

src/index.js

@@ -7,2 +7,5 @@ const cookie = require("cookie");

willSendResponse(requestContext) {
const { setHeaders = [], setCookies = [] } = requestContext.context;
// inform user about wrong usage
if (!Array.isArray(requestContext.context.setHeaders)) {

@@ -14,5 +17,8 @@ console.warn("setHeaders is not in context or is not an array");

}
if (setCookies.length > 1) {
// dont allow to set multiple cookies because that wouldnt work (limitation in apollo-server)
throw new Error("multiple cookies in setCookies provided but because of limitations in apollo-server only one cookie can be set");
}
const { setHeaders = [], setCookies = [] } = requestContext.context;
// set headers
setHeaders.forEach(({ key, value }) => {

@@ -23,5 +29,6 @@ requestContext.response.http.headers.append(key, value);

// set cookies
setCookies.forEach(({ name, value, options }) => {
var cookieString = cookie.serialize(name, value, options);
requestContext.response.http.headers.append("Set-Cookie", cookieString);
requestContext.response.http.headers.set("Set-Cookie", cookieString);
console.debug("set header Set-Cookie: " + cookieString);

@@ -28,0 +35,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc