0

I am currently starting with Angular. With my team we are preparing some POC to exchange views in our app. Long story short - we're using other team's module with all the mechanism sending responses and so on, so our job in backend is only to create endpoint, get data, and invoke proper method from this 'other team's module'. Last time they have changed content-encoding from "UTF-8" to "gzip, deflate" and since that our Angular rest calls stopped working. Every request sent to backend results with:

net::ERR_CONTENT_DECODING_FAILED 200 (OK)
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error"

I changed this backend REST module back to sending response with encoding "UTF-8" and everything went back to working properly.

I looked like everywhere for last few days and did not figure it out in any way. Here's some code:

call for endpoint:

private loadResulst() {
  const URL = '/results/v1';
  this.apiService.getResource(URL).subscribe(data => {
    let newValues = [{id: 0, name:''}]
    data['resultList'].forEach((value: string, index: number) => {
      newValues.push({ id: index + 1, name: value });
    })
    this.results = newValues;
  });
}

apiService.getResource:

getResource(resourceUrl: string): Observable<Object> {
  const httpOptions = { headers: this.headers };
  return this.httpClient.get(this.apiUrl + resourceUrl, httpOptions);
}

request headers:

Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,pl;q=0.8
Connection: keep-alive
Host: localhost:4200
Referer: http://localhost:4200/
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

response headers:

Access-Control-Allow-Origin: *
connection: close
content-encoding: deflate, gzip
content-length: 69
content-type: application/json
date: Fri, 21 Feb 2020 07:59:11 GMT
server: Apache-Coyote/1.1
X-Powered-By: Express
x-ua-compatible: IE=9

When approaching data via Postman with the very same headers I get data without any problems.

Bartosz Gniado
  • 53
  • 1
  • 2
  • 7

1 Answers1

0

Found out. According to this SO topic, "It happens when your HTTP request's headers claim that the content is gzip encoded, but it isn't."

Bartosz Gniado
  • 53
  • 1
  • 2
  • 7