Getting an incomplete (chunked) JSON response on Angular proxy

747 views
Skip to first unread message

Koen Verhulst

unread,
Sep 4, 2019, 1:41:33 PM9/4/19
to Angular and AngularJS discussion
Hi,

While developing an Angular 7 web app, I am using the proxy.conf.json file and --proxy-config option on the ng serve command to proxy 
my requests from https://localhost:4200/api to a remote url which hosts the actual REST API.

When doing an HTTP GET request directly to the remote url through my browser (Chrome) or Postman, I always get the full (valid) JSON response 
like I expect it to be. 

In order to simulate the problem, I created a (local) endpoint (localhost:8080/sample) which returns a huge json:

[
   "This is line 0",
   "This is line 1",
   "This is line 2",
...
    "This is line 199997",
   "This is line 199998",
   "This is line 199999"
]

When requesting this on the angular proxy url, I get only a part of the JSON response or an invalid JSON, with values 
I did not expected:

 ...
 
"This is line 126439",
 
"This is line 126440"s line 126813","This is line 126814",

I am aware that the API returns response header Transfer-encoding 'chunked' and from what I understand, 
this means having to process the response as a stream.

Anyone seen this strange issue before?

I would like to retrieve a valid, correct JSON over the angular proxy without changing the API.

Kind regards,

Koen

Sander Elias

unread,
Sep 5, 2019, 12:41:36 AM9/5/19
to Angular and AngularJS discussion
Hi Koen,

I'm afraid that's an issue of the proxy server that's included in the CLI. I had some similar issues and had to put another proxy in place to get rid of this issue.
Another way might be is (for test env) disable chunking in your server.

If you have a small repo that easily demonstrates the issue in a reproducible way, you can raise an issue on Angular's GitHub. But they really need a way to reproduce, otherwise, it's not something that will get a fix. 

Regards
Sander
Reply all
Reply to author
Forward
0 new messages