kaazing / http2-cache.js

2 stars 11 forks source link

implement partial FormData support #28

Closed hthetiot closed 7 years ago

hthetiot commented 7 years ago

Allow FormData to Socket.

Example:

var formData = new FormData();
formData.append('username', 'Chris');
formData.append('username', 'Bob');
formData.append('gender', 'male');  

xhr.send(formData);

Also fix missing headers on non proxy xhr.

tejaede commented 7 years ago

Hi @hthetiot

Jonathan & I found that the FormData fix did not work for both Proxied & Non proxied requests. We instead moved the serializeXhrBody() call into the if block so that it is only used for proxied requests. Do you have any concerns about that?

redefine(xhrProto, 'send', function (body) {
        var url = xhrInfo.get(this, 'url');
        var self = this;

        // Also fix support for node-http2 FormData
        //Priov
        // body = serializeXhrBody(body);

        if (configuration.isConfiguring()) {
            //removed for brevity
        } else {

            var destination = parseUrl(url);
            var proxyTransportUrl = configuration.getTransportUrl(destination);
            if (proxyTransportUrl) {
                if (configuration.debug) {
                    configuration._log.debug("Proxying XHR(" + url + ") via " + proxyTransportUrl);
                }

                body = serializeXhrBody(body); 
                this._sendViaHttp2(destination, body, proxyTransportUrl);
            } else {
                if (configuration.debug) {
                    configuration._log.debug("Sending XHR(" + url + ") via native stack");
                }
                this._open(xhrInfo.get(this, 'method'),
                    url,
                    xhrInfo.get(this, 'async'),
                    xhrInfo.get(this, 'username'),
                    xhrInfo.get(this, 'password'));
                // TODO set headers
                this._send(body);
            }

        }
    });
tejaede commented 7 years ago

https://github.com/kaazing/http2-cache.js/pull/30