TCPClient.available() does not return length

look at the following example: https://gist.github.com/synox/b049a88bb533d7c3ec4c

it works when using a delay(2000) before reading the response. without the delay it doesn’t work. any idea how to make the coder better?

Can someone please post a complete http example?