Skip to content

Commit 28a97e4

Browse files
authored
fix(core): replace headers.get('cookie') with headers.cookie (#347)
1 parent 085bbae commit 28a97e4

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ Only install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) fo
108108
with this
109109

110110
```typescript
111+
import { REQUEST } from '@angular/core';
112+
111113
server.get('*', (req, res) => {
112114
res.render(indexHtml, {
113115
req,
114116
providers: [
115117
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
116-
{ provide: 'REQUEST', useValue: req },
117-
{ provide: 'RESPONSE', useValue: res },
118+
{ provide: REQUEST, useValue: req }
118119
],
119120
});
120121
});
@@ -284,6 +285,7 @@ Thanks to all contributors:
284285
- [IceBreakerG](https://github.com/IceBreakerG)
285286
- [rojedalopez](https://github.com/rojedalopez)
286287
- [Nikel163](https://github.com/Nikel163)
288+
- [Martin Evtimov](https://github.com/mmart1n)
287289

288290
# License
289291

projects/ngx-cookie-service-ssr/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ Only install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) fo
132132
with this
133133

134134
```typescript
135+
import { REQUEST } from '@angular/core';
136+
135137
server.get('*', (req, res) => {
136138
res.render(indexHtml, {
137139
req,
138140
providers: [
139141
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
140-
{ provide: 'REQUEST', useValue: req },
141-
{ provide: 'RESPONSE', useValue: res },
142+
{ provide: REQUEST, useValue: req }
142143
],
143144
});
144145
});
@@ -317,6 +318,7 @@ Thanks to all contributors:
317318
- [IceBreakerG](https://github.com/IceBreakerG)
318319
- [rojedalopez](https://github.com/rojedalopez)
319320
- [Nikel163](https://github.com/Nikel163)
321+
- [Martin Evtimov](https://github.com/mmart1n)
320322

321323
# License
322324

projects/ngx-cookie-service-ssr/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
},
7373
{
7474
"name": "IceBreakerG"
75+
},
76+
{
77+
"name": "Martin Evtimov"
7578
}
7679
],
7780
"repository": {

projects/ngx-cookie-service-ssr/src/lib/ssr-cookie.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export class SsrCookieService {
5656
check(name: string): boolean {
5757
name = encodeURIComponent(name);
5858
const regExp: RegExp = SsrCookieService.getCookieRegExp(name);
59-
return regExp.test(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
59+
return regExp.test(this.documentIsAccessible ?
60+
this.document.cookie :
61+
(this.request?.headers.cookie ?? this.request?.headers.get('cookie'))
62+
);
6063
}
6164

6265
/**
@@ -72,7 +75,10 @@ export class SsrCookieService {
7275
if (this.check(name)) {
7376
name = encodeURIComponent(name);
7477
const regExp: RegExp = SsrCookieService.getCookieRegExp(name);
75-
const result = regExp.exec(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
78+
const result = regExp.exec(this.documentIsAccessible ?
79+
this.document.cookie :
80+
(this.request?.headers.cookie ?? this.request?.headers.get('cookie'))
81+
);
7682
return result && result[1] ? SsrCookieService.safeDecodeURIComponent(result[1]) : '';
7783
}
7884
return '';
@@ -88,7 +94,9 @@ export class SsrCookieService {
8894
*/
8995
getAll(): { [key: string]: string } {
9096
const cookies: { [key: string]: string } = {};
91-
const cookieString: any = this.documentIsAccessible ? this.document?.cookie : this.request?.headers.get('cookie');
97+
const cookieString: any = this.documentIsAccessible ?
98+
this.document?.cookie :
99+
(this.request?.headers.cookie ?? this.request?.headers.get('cookie'));
92100

93101
if (cookieString && cookieString !== '') {
94102
cookieString.split(';').forEach((currentCookie: string) => {

projects/ngx-cookie-service/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ Only install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) fo
132132
with this
133133

134134
```typescript
135+
import { REQUEST } from '@angular/core';
136+
135137
server.get('*', (req, res) => {
136138
res.render(indexHtml, {
137139
req,
138140
providers: [
139141
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
140-
{ provide: 'REQUEST', useValue: req },
141-
{ provide: 'RESPONSE', useValue: res },
142+
{ provide: REQUEST, useValue: req }
142143
],
143144
});
144145
});
@@ -317,6 +318,7 @@ Thanks to all contributors:
317318
- [IceBreakerG](https://github.com/IceBreakerG)
318319
- [rojedalopez](https://github.com/rojedalopez)
319320
- [Nikel163](https://github.com/Nikel163)
321+
- [Martin Evtimov](https://github.com/mmart1n)
320322

321323
# License
322324

0 commit comments

Comments
 (0)