Github user Jens-G commented on a diff in the pull request:
https://github.com/apache/thrift/pull/1045#discussion_r71064971
--- Diff: lib/haxe/src/org/apache/thrift/transport/THttpClient.hx ---
@@ -94,10 +114,241 @@ class THttpClient extends TTransport {
}
};
+ #if js
+ request_.onBinaryData = function(data : Bytes) {
+ responseBuffer_ = new BytesInput(data);
+ if( callback != null) {
+ callback(null);
+ }
+ };
+
+ request_.setBinaryPostData(buffer.getBytes());
+ #else
request_.setPostData(buffer.getBytes().toString());
+ #end
request_.request(true/*POST*/);
}
-
}
-
\ No newline at end of file
+#if js
+/*supports sending/receiving binary/json data (browser, nodejs)
+ implemented atop
https://github.com/HaxeFoundation/haxe/blob/development/std/haxe/Http.hx
+ */
+class JsHttp extends Http {
+ var binaryPostData : Bytes;
+
+ public function setBinaryPostData( data : Bytes ):Http {
+ binaryPostData = data;
+ return this;
+ }
+
+ public dynamic function onBinaryData( data : Bytes ) {
+ }
+
+ #if !nodejs
+ public override function request( ?post : Bool ) : Void {
+ var me = this;
+ me.responseData = null;
+ var r = req = js.Browser.createXMLHttpRequest();
+ var onreadystatechange = function(_) {
+ if( r.readyState != 4 )
+ return;
+ var s = try r.status catch( e : Dynamic ) null;
+ if ( s != null && untyped __js__('"undefined" !== typeof
window') ) {
+ // If the request is local and we have data: assume a
success (jQuery approach):
+ var protocol = js.Browser.location.protocol.toLowerCase();
+ var rlocalProtocol =
~/^(?:about|app|app-storage|.+-extension|file|res|widget):$/;
+ var isLocal = rlocalProtocol.match( protocol );
+ if ( isLocal ) {
+ s = r.responseText != null ? 200 : 404;
+ }
+ }
+ if( s == untyped __js__("undefined") )
+ s = null;
+ if( s != null )
+ me.onStatus(s);
+ if( s != null && s >= 200 && s < 400 ) {
+ me.req = null;
+ var len = r.responseText.length;
+ var bytes = new BytesOutput();
+ bytes.prepare(len);
+ for(i in 0 ... len) {
+ var byte = (r.responseText.charCodeAt(i) & 255);
+ if(byte >= 128) {
+ byte -= 256;
+ }
+ bytes.writeInt8(byte);
+ }
+ var resBytes = bytes.getBytes();
+ me.onBinaryData(resBytes);
+ }
+ else if ( s == null ) {
+ me.req = null;
+ me.onError("Failed to connect or resolve host");
+ }
+ else switch( s ) {
+ case 12029:
+ me.req = null;
+ me.onError("Failed to connect to host");
+ case 12007:
+ me.req = null;
+ me.onError("Unknown host");
+ default:
+ me.req = null;
+ me.responseData = r.responseText;
+ me.onError("Http Error #"+r.status);
+ }
+ };
+ if( async )
+ r.onreadystatechange = onreadystatechange;
+ var uri = postData;
+ var jsData = binaryPostData;
+ if( jsData != null )
+ post = true;
+ else for( p in params ) {
+ if( uri == null )
+ uri = "";
+ else
+ uri += "&";
+ uri +=
StringTools.urlEncode(p.param)+"="+StringTools.urlEncode(p.value);
+ }
+ try {
+ if( post )
+ r.open("POST",url,async);
+ else if( uri != null ) {
+ var question = url.split("?").length <= 1;
+ r.open("GET",url+(if( question ) "?" else "&")+uri,async);
+ uri = null;
+ } else
+ r.open("GET",url,async);
+ } catch( e : Dynamic ) {
--- End diff --
Then we need to fix that first, and I can't commit it. Thrift is about
talking cross-language and cross-platform, not about one
system/machine/language talking to itself. I tested the original implementation
against C#, Delphi and Go, crossing Windows and Linux borders, and it worked.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---