[SalesForce] How to know the Rest Request and Response size

I am writing an Apex Rest web service and I do not want to hit the cap of 6 MB on request or response payload or the 12 MB limit for asynchronous APEX.

But the size of the request and responses are not logged in the Debug Logs. Do I have to adjust the Debug Level to get it logged? If not, how can I view them?

Edit:
Here is my Apex Rest Web Service Method signature. Can I or can I not hit Salesforce 6 MB limits with this?

    @HttpPatch
    global static String updateBusinessPartner(List<BusinessPartnerUpdatedInfo> businessPartnerList) {
        //some processing here
    RestRequest incomingRequest = RestContext.request;
    System.debug('incomingRequest body:' + incomingRequest.requestBody);//prints null 
    //all the data of the request is inside the List object in the method parameter. requestBody is NULL
    }

How do I get the incoming request size?

Best Answer

You can Use HTTPRequest and HTTPResponse class method getBodyAsBlob(); to get the response body in blob and then you can check the size.

httpRequest.getBodyAsBlob().size();

httpResponse.getBodyAsBlob().size();

Then you can use this size in your code.