ApacheHTTPResponse(
            final HttpClient client,
            final BOSHClientConfig cfg,
            final CMSessionParams params,
            final AbstractBody request) {
        super();
        this.client = client;
        this.context = new BasicHttpContext();
        this.post = new HttpPost(cfg.getURI().toString());
        this.sent = false;

        try {
            String xml = request.toXML();
            byte[] data = xml.getBytes(CHARSET);

            String encoding = null;
            if (cfg.isCompressionEnabled() && params != null) {
                AttrAccept accept = params.getAccept();
                if (accept != null) {
                    if (accept.isAccepted(ZLIBCodec.getID())) {
                        encoding = ZLIBCodec.getID();
                        data = ZLIBCodec.encode(data);
                    } else if (accept.isAccepted(GZIPCodec.getID())) {
                        encoding = GZIPCodec.getID();
                        data = GZIPCodec.encode(data);
                    }
                }
            }

            ByteArrayEntity entity = new ByteArrayEntity(data);
            entity.setContentType(CONTENT_TYPE);
            if (encoding != null) {
                entity.setContentEncoding(encoding);
            }
            post.setEntity(entity);
            if (cfg.isCompressionEnabled()) {
                post.setHeader(ACCEPT_ENCODING, ACCEPT_ENCODING_VAL);
            }
        } catch (Exception e) {
            toThrow = new BOSHException("Could not generate request", e);
        }
    }