[
https://issues.apache.org/jira/browse/THRIFT-3876?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15380308#comment-15380308
]
ASF GitHub Bot commented on THRIFT-3876:
----------------------------------------
Github user oprudkyi commented on a diff in the pull request:
https://github.com/apache/thrift/pull/1045#discussion_r71054064
--- 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 --
as for me haxe has never worked with other langs
> haxe js/nodejs client
> ---------------------
>
> Key: THRIFT-3876
> URL: https://issues.apache.org/jira/browse/THRIFT-3876
> Project: Thrift
> Issue Type: Improvement
> Components: Haxe - Library
> Reporter: Oleksii Prudkyi
> Assignee: Oleksii Prudkyi
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)