Let say that dealing with AT command is really frustrating, because you have to deal with an additional layer to communicate between your external MCU and the ESP. Maybe you should try using ArduinoESP instead, there are plenty of example of code, and a simple WebServer is there too since it is what you seems to look for. You won't need to deal with those length calculation since the basic helper functions will handle it themselves.
Let say that dealing with AT command is really frustrating, because you have to deal with an additional layer to communicate between your external MCU and the ESP. Maybe you should try using ArduinoESP instead, there are plenty of example of code, and a simple WebServer is there too since it is what you seems to look for. You won't need to deal with those length calculation since the basic helper functions will handle it themselves.