0
votes

I am trying to add a content-length header to my rest response as it's coming back 'chunked'.

	@HttpGet
	 global static RESTBase getCatalog() {
	  RestRequest req = RestContext.request;
	  RestResponse resp = RestContext.response;
	  Map < String, string > respHeader = new Map < String, string > ();

	  String storeId = req.requestURI.substring(req.requestURI.lastIndexOf('/') + 1);
	  Store__c currentStore = QueryUtils.getStoreFromStoreNumber(storeId);
	  if (currentStore == null) {
	    CatalogResponse catalogResponse = new CatalogResponse();

	    catalogResponse.Status = '404';

	    return catalogResponse;
	  }

	  Map < String, PricebookEntry > priceBookEntries = getPriceBookEntriesForPriceBook(currentStore.Price_Book__c);
	  List < TriCom__Category__c > rootCategories = getRootProductCategories();
	  Map < String, List < UPC_Code__c >> upcCodeMap = getUPCCodeMap();

	  RESTCatalog catalog = new RESTCatalog();

	  catalog.PriceBookId = currentStore.Price_Book__c;
	  catalog.StoreNumber = currentStore.Name;
	  catalog.Categories = createRestCategory(rootCategories, upcCodeMap, priceBookEntries);
       
	  String returnJson = JSON.serialize(catalog);
       
	  resp.addHeader('Content-Length', String.valueOf(returnJson.length()));

	  return catalog;
	}

When I do a get request I get back:

"errorCode": "APEX_ERROR",
"message": "System.InvalidHeaderException: Header name \"Content-Length\" is not allowed.\\\n\\\n(System Code)\

Any advice is appreciated.

1
You don't need to set the content-length, it'll be set for you by the framework. - superfell

1 Answers

1
votes

Salesforce will set content-length automatically. It is actually documented that this header cannot be set.