Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Server side requests using HttpClient don't support GZIP encoding #1055

Closed
luxalpa opened this issue Aug 20, 2018 · 5 comments
Closed

Server side requests using HttpClient don't support GZIP encoding #1055

luxalpa opened this issue Aug 20, 2018 · 5 comments

Comments

@luxalpa
Copy link

luxalpa commented Aug 20, 2018

I'm trying to request some API using the HttpClient on my app.server.module.ts.

this.http.get(`https://apis.justwatch.com/content/translations/en_US?prefix=WEBAPP_&translatable_type=ui_string`)

if I use responseType: 'text' then it works although the data is still gzipped and I can't parse it as json. Otherwise I get this error:

PS C:\dev\projects\angular\ssr-test> yarn serve:ssr
yarn run v1.9.4
$ node dist/server
Node server listening on http://localhost:4000
ERROR HttpErrorResponse {
  headers:
   HttpHeaders {
     normalizedNames: Map {},
     lazyUpdate: null,
     lazyInit: [Function] },
  status: 200,
  statusText: 'OK',
  url: 'https://apis.justwatch.com/content/translations/en_US?prefix=WEBAPP_&translatable_type=ui_string',
  ok: false,
  name: 'HttpErrorResponse',
  message: 'Http failure during parsing for https://apis.justwatch.com/content/translations/en_US?prefix=WEBAPP_&translatable_type=ui_string',
  error:
   { error: SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.onLoad (C:\dev\projects\angular\ssr-test\dist\server.js:71535:51)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\dev\projects\angular\ssr-test\dist\server.js:127163:20)
    at XMLHttpRequest._dispatchProgress (C:\dev\projects\angular\ssr-test\dist\server.js:127658:12)
    at XMLHttpRequest._onHttpResponseEnd (C:\dev\projects\angular\ssr-test\dist\server.js:127613:12)
    at IncomingMessage.<anonymous> (C:\dev\projects\angular\ssr-test\dist\server.js:127572:24)
    at ZoneDelegate.invokeTask (C:\dev\projects\angular\ssr-test\dist\server.js:553:31)
    at Object.onInvokeTask (C:\dev\projects\angular\ssr-test\dist\server.js:7710:33)
    at ZoneDelegate.invokeTask (C:\dev\projects\angular\ssr-test\dist\server.js:552:36)
    at Zone.runTask (C:\dev\projects\angular\ssr-test\dist\server.js:320:47),
     text: '\u001f�\b\u0000\u0000\u0000\u0000\u0000\ ... and so on

The same code works flawlessly on the browser.

Angular version: 6.1.3
Node.js version: 9.2.0

Motivation: I want to request translation files from our API and render them for SEO purposes.

@luxalpa
Copy link
Author

luxalpa commented Aug 22, 2018

Part of the issue is that our Web API for some reason occasionally ignored the Accept-Encoding header and just delivered gzipped content (with proper Content-Encoding) anyway. So, to have XHRHttpRequests work like they do in the browser, I think we need to support the GZIP and I think in general it would be a good thing to support it really.

@luxalpa
Copy link
Author

luxalpa commented Aug 23, 2018

Related: pwnall/node-xhr2#17

@CaerusKaru
Copy link
Member

Issue will be tracked exclusively in node-xhr2. We can upgrade to the newer version when it's published; when this happens, please open an issue on angular/angular since that's where the dependency lives.

@ssatz
Copy link

ssatz commented Nov 18, 2018

@destructive-dragon : I am facing the same issue here. How to solve this? same angular version here as well

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants