Fossil SCM
added preliminary support for cookies in the rhino ajax client, but it does not seem to be doing anything.
Commit
ef9d8393117532707b2e93b04c5cf7cb6f30ec60
Parent
a36d5c0ed89cd17…
1 file changed
+30
-1
+30
-1
| --- ajax/js/whajaj.js | ||
| +++ ajax/js/whajaj.js | ||
| @@ -887,10 +887,11 @@ | ||
| 887 | 887 | requires the ability to kill a running thread (which is deprecated |
| 888 | 888 | in the Java API). |
| 889 | 889 | */ |
| 890 | 890 | rhino:function(request,args) |
| 891 | 891 | { |
| 892 | + var self = this; | |
| 892 | 893 | var data = request || undefined; |
| 893 | 894 | if( data ) { |
| 894 | 895 | if('string'!==typeof data) { |
| 895 | 896 | try { |
| 896 | 897 | data = JSON.stringify(data); |
| @@ -904,14 +905,42 @@ | ||
| 904 | 905 | var url; |
| 905 | 906 | var con; |
| 906 | 907 | var IO = new JavaImporter(java.io); |
| 907 | 908 | var wr; |
| 908 | 909 | var rd, ln, json = []; |
| 910 | + function setIncomingCookies(list){ | |
| 911 | + if(!list || !list.length) return; | |
| 912 | + if( !self.cookies ) self.cookies = {}; | |
| 913 | + var k, v, i; | |
| 914 | + for( i = 0; i < list.length; ++i ){ | |
| 915 | + v = list[i].split('=',2); | |
| 916 | + k = decodeURIComponent(v[0]) | |
| 917 | + v = v[0] ? decodeURIComponent(v[0].split(';',2)[0]) : null; | |
| 918 | + //print("RECEIVED COOKIE: "+k+"="+v); | |
| 919 | + if(!v) { | |
| 920 | + delete self.cookies[k]; | |
| 921 | + continue; | |
| 922 | + }else{ | |
| 923 | + self.cookies[k] = v; | |
| 924 | + } | |
| 925 | + } | |
| 926 | + }; | |
| 927 | + function setOutboundCookies(conn){ | |
| 928 | + if(!self.cookies) return; | |
| 929 | + var k, v; | |
| 930 | + for( k in self.cookies ){ | |
| 931 | + if(!self.cookies.hasOwnProperty(k)) continue /*kludge for broken JS libs*/; | |
| 932 | + v = self.cookies[k]; | |
| 933 | + conn.addRequestProperty("Cookie", encodeURIComponent(k)+'='+encodeURIComponent(v)); | |
| 934 | + //print("SENDING COOKIE: "+k+"="+v); | |
| 935 | + } | |
| 936 | + }; | |
| 909 | 937 | try{ |
| 910 | 938 | url = new java.net.URL( args.url ) |
| 911 | 939 | con = url.openConnection(/*FIXME: add proxy support!*/); |
| 912 | 940 | con.setRequestProperty("Accept-Charset","utf-8"); |
| 941 | + setOutboundCookies(con); | |
| 913 | 942 | if(data){ |
| 914 | 943 | con.setRequestProperty("Content-Type","application/json; charset=utf-8"); |
| 915 | 944 | con.setDoOutput( true ); |
| 916 | 945 | wr = new IO.OutputStreamWriter(con.getOutputStream()) |
| 917 | 946 | wr.write(data); |
| @@ -929,11 +958,11 @@ | ||
| 929 | 958 | // json = []; |
| 930 | 959 | // continue; |
| 931 | 960 | //} |
| 932 | 961 | json.push(line); |
| 933 | 962 | } |
| 934 | - | |
| 963 | + setIncomingCookies(con.getHeaderFields().get("Set-Cookie")); | |
| 935 | 964 | }catch(e){ |
| 936 | 965 | args.errorMessage = e.toString(); |
| 937 | 966 | WhAjaj.Connector.sendHelper.onSendError( request, args ); |
| 938 | 967 | return undefined; |
| 939 | 968 | } |
| 940 | 969 |
| --- ajax/js/whajaj.js | |
| +++ ajax/js/whajaj.js | |
| @@ -887,10 +887,11 @@ | |
| 887 | requires the ability to kill a running thread (which is deprecated |
| 888 | in the Java API). |
| 889 | */ |
| 890 | rhino:function(request,args) |
| 891 | { |
| 892 | var data = request || undefined; |
| 893 | if( data ) { |
| 894 | if('string'!==typeof data) { |
| 895 | try { |
| 896 | data = JSON.stringify(data); |
| @@ -904,14 +905,42 @@ | |
| 904 | var url; |
| 905 | var con; |
| 906 | var IO = new JavaImporter(java.io); |
| 907 | var wr; |
| 908 | var rd, ln, json = []; |
| 909 | try{ |
| 910 | url = new java.net.URL( args.url ) |
| 911 | con = url.openConnection(/*FIXME: add proxy support!*/); |
| 912 | con.setRequestProperty("Accept-Charset","utf-8"); |
| 913 | if(data){ |
| 914 | con.setRequestProperty("Content-Type","application/json; charset=utf-8"); |
| 915 | con.setDoOutput( true ); |
| 916 | wr = new IO.OutputStreamWriter(con.getOutputStream()) |
| 917 | wr.write(data); |
| @@ -929,11 +958,11 @@ | |
| 929 | // json = []; |
| 930 | // continue; |
| 931 | //} |
| 932 | json.push(line); |
| 933 | } |
| 934 | |
| 935 | }catch(e){ |
| 936 | args.errorMessage = e.toString(); |
| 937 | WhAjaj.Connector.sendHelper.onSendError( request, args ); |
| 938 | return undefined; |
| 939 | } |
| 940 |
| --- ajax/js/whajaj.js | |
| +++ ajax/js/whajaj.js | |
| @@ -887,10 +887,11 @@ | |
| 887 | requires the ability to kill a running thread (which is deprecated |
| 888 | in the Java API). |
| 889 | */ |
| 890 | rhino:function(request,args) |
| 891 | { |
| 892 | var self = this; |
| 893 | var data = request || undefined; |
| 894 | if( data ) { |
| 895 | if('string'!==typeof data) { |
| 896 | try { |
| 897 | data = JSON.stringify(data); |
| @@ -904,14 +905,42 @@ | |
| 905 | var url; |
| 906 | var con; |
| 907 | var IO = new JavaImporter(java.io); |
| 908 | var wr; |
| 909 | var rd, ln, json = []; |
| 910 | function setIncomingCookies(list){ |
| 911 | if(!list || !list.length) return; |
| 912 | if( !self.cookies ) self.cookies = {}; |
| 913 | var k, v, i; |
| 914 | for( i = 0; i < list.length; ++i ){ |
| 915 | v = list[i].split('=',2); |
| 916 | k = decodeURIComponent(v[0]) |
| 917 | v = v[0] ? decodeURIComponent(v[0].split(';',2)[0]) : null; |
| 918 | //print("RECEIVED COOKIE: "+k+"="+v); |
| 919 | if(!v) { |
| 920 | delete self.cookies[k]; |
| 921 | continue; |
| 922 | }else{ |
| 923 | self.cookies[k] = v; |
| 924 | } |
| 925 | } |
| 926 | }; |
| 927 | function setOutboundCookies(conn){ |
| 928 | if(!self.cookies) return; |
| 929 | var k, v; |
| 930 | for( k in self.cookies ){ |
| 931 | if(!self.cookies.hasOwnProperty(k)) continue /*kludge for broken JS libs*/; |
| 932 | v = self.cookies[k]; |
| 933 | conn.addRequestProperty("Cookie", encodeURIComponent(k)+'='+encodeURIComponent(v)); |
| 934 | //print("SENDING COOKIE: "+k+"="+v); |
| 935 | } |
| 936 | }; |
| 937 | try{ |
| 938 | url = new java.net.URL( args.url ) |
| 939 | con = url.openConnection(/*FIXME: add proxy support!*/); |
| 940 | con.setRequestProperty("Accept-Charset","utf-8"); |
| 941 | setOutboundCookies(con); |
| 942 | if(data){ |
| 943 | con.setRequestProperty("Content-Type","application/json; charset=utf-8"); |
| 944 | con.setDoOutput( true ); |
| 945 | wr = new IO.OutputStreamWriter(con.getOutputStream()) |
| 946 | wr.write(data); |
| @@ -929,11 +958,11 @@ | |
| 958 | // json = []; |
| 959 | // continue; |
| 960 | //} |
| 961 | json.push(line); |
| 962 | } |
| 963 | setIncomingCookies(con.getHeaderFields().get("Set-Cookie")); |
| 964 | }catch(e){ |
| 965 | args.errorMessage = e.toString(); |
| 966 | WhAjaj.Connector.sendHelper.onSendError( request, args ); |
| 967 | return undefined; |
| 968 | } |
| 969 |