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

breaks if Cache-Control is array #28

Open
gajus opened this issue Feb 5, 2020 · 2 comments
Open

breaks if Cache-Control is array #28

gajus opened this issue Feb 5, 2020 · 2 comments

Comments

@gajus
Copy link

gajus commented Feb 5, 2020

curl -v https://www.reservaentradas.com/cines
< HTTP/1.1 200 OK
< Date: Wed, 05 Feb 2020 18:51:26 GMT
< Server: Apache/2.2.22 (Debian)
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Vary: Accept-Encoding
< Cache-Control: max-age=0, no-cache
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
<

Produces error:

TypeError: header.trim is not a function
          at parseCacheControl (/Users/gajus/Documents/dev/rayroute/rayman/node_modules/http-cache-semantics/index.js:62:26)
          at new CachePolicy (/Users/gajus/Documents/dev/rayroute/rayman/node_modules/http-cache-semantics/index.js:119:23)
          at action (/Users/gajus/Documents/dev/rayroute/rayman/src/interceptors/createCacheInterceptor/index.js:68:27)
          at Object.responseActions (/Users/gajus/Documents/dev/rayroute/rayman/node_modules/@rayroute/raygun/src/factories/createInterceptorActions.js:152:22)
          at processTicksAndRejections (internal/process/task_queues.js:97:5)
          at handleRequest (/Users/gajus/Documents/dev/rayroute/rayman/node_modules/@rayroute/raygun/src/factories/createRequestHandler.js:69:28)
@kornelski
Copy link
Owner

Oops, indeed!

Could you make it detect non-string header value and run join(',') on it?

@gajus
Copy link
Author

gajus commented Feb 5, 2020

That is indeed how I have patched it locally.

+const normalizeHeaders = (headers: HeadersType): HeadersType => {
+  const normalizedHeaders = {
+    ...headers,
+  };
+
+  // @see https://github.com/kornelski/http-cache-semantics/issues/28
+  if (Array.isArray(normalizedHeaders['cache-control'])) {
+    normalizedHeaders['cache-control'] = normalizedHeaders['cache-control'].join(', ');
+  }
+
+  return normalizedHeaders;
+};
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants