I kind of fixed it by not letting the request String get too big. I now check if the request endsWith HTTP/, and if so, stop adding chars to the string.
request.endsWith("HTTP/")
I, however, think this is a rather dirty solution and should not be used?