Sounds like a fun and challenging project!
To do this the right way you'll have to read the byte count in the chunk header and collect that much OR a fixed value, rather than collecting a fixed value all the time. This way your loop can be sure to exit at the right time. The last line in a chunked response is always "0\r\n", and you can also test for that to make sure the response is completed.
One other gotcha here is that there are architectural oddities about how BIG-IP's HTTP profile works with HTTP chunk mode together with HTTP compression to coordinate traffic between the server-side and client-side halves of the flow. If you find something weird, try turning off chunk mode, or compression, or both.
One trick I've used successfully in the past is to avoid chunked mode altogether by using iRules to remove or modify the "accept-encoding" header so that the HTTP participants assume the other one doesn't support it. Clients and servers will usually fall back to normal Content-Length mode if instructed to.