private void awaitResponse() throws BOSHException {
            // Synchronize to take a reference to the connection.  If another
            // thread calls abort() it may abort the connection and set
            // connection to null.
            InternalHTTPConnection<InternalHTTPResponse> connection;
            synchronized(HTTPSenderInternal.this) {
                if(toThrow != null)
                    throw toThrow;
                // If we already have a response, stop.

                if(body != null)
                    return;

                connection = this.connection;
            }

            // At this point, we can safely access connection's methods, which are threadsafe,
            // but we can't access conn.
            InternalHTTPConnection.ResponseData response;
            try {
                response = connection.waitForNextResponse();
                if(response.request != this)
                    throw new RuntimeException("Received a response that wasn't for us");

                byte[] data = response.data;

                String encoding = response.getResponseHeader("Content-Encoding");
                if (ZLIBCodec.getID().equalsIgnoreCase(encoding))
                    data = ZLIBCodec.decode(data);
                else if (GZIPCodec.getID().equalsIgnoreCase(encoding))
                    data = GZIPCodec.decode(data);

                String bodyData = new String(data, "UTF-8");

                body = StaticBody.fromString(bodyData);
                statusCode = response.statusCode;
            } catch (IOException e) {
                throw abortWithError(new BOSHException("Could not obtain response", e));
            }

            // After a response, detect whether keepalives are supported.  Don't support keepalives
            // for HTTP/1.0 servers; there shouldn't be any, and we'd have to handle max keepalives
            // to handle it.
            if(response.majorVersion == 1 && response.minorVersion == 0)
                supportsKeepAlive = false;
            else if(response.getResponseHeader("Connection").equalsIgnoreCase("close"))
                supportsKeepAlive = false;
            else
                supportsKeepAlive = true;

            // Tell HTTPSenderInternal that we're done.  Don't call this with this object locked.
            InternalHTTPConnection<InternalHTTPResponse> finishedConnection = null;
            synchronized(HTTPSenderInternal.this) {
                finishedConnection = connection;
                connection = null;
            }
            requestCompleted(finishedConnection, true);
        }