function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bruce_DoBruce_Do 

How to change Transfer-Encoding Salesforce REST API

I'm implement a Rest API that return an attachment file. But the respone always return Transfer-Encoding: chunked. As you know, with this type, the Content-Length will not return. I need the Content-Length to show progess bar at client side.
But when I change the Transfer-Encoding to other types like gzip, deflate,compress, identity. The respone always return error: We are down for maintenance.
Please help to show me the way to change this, or how can I set the Content-Length
my code code look like this
RestResponse res = RestContext.response;
String result = JSON.serialize('<the object content>');
String contentLength = String.valueOf(Blob.valueOf(result));
res.responseBody = Blob.valueOf(result);
//res.addHeader('Transfer-Encoding', 'gzip');// this line will get error: We are down for maintenance. So I comment it out.
//res.addHeader('Content-Length', '' + contentLength.length()); // this line will get error also b/c Content-Length cannot not set manual

and the respone will like this
cache-control →s-maxage=0
content-type →application/json;charset=UTF-8
date →Tue, 10 Oct 2017 03:18:35 GMT
transfer-encoding →chunked
x-xss-protection →1; mode=block
I want Content-Length return on the header, but it does not when ransfer-encoding -> chunked.