1- "0.30 .0" ;
1+ "0.31 .0" ;
22/*
33CryptoJS v3.0.2
44code.google.com/p/crypto-js
@@ -1773,6 +1773,17 @@ TinCan client library
17731773 this . log ( "_makeRequest not overloaded - no environment loaded?" ) ;
17741774 } ,
17751775
1776+ /**
1777+ Method is overloaded by the browser environment in order to test converting an
1778+ HTTP request that is greater than a defined length
1779+
1780+ @method _IEModeConversion
1781+ @private
1782+ */
1783+ _IEModeConversion : function ( ) {
1784+ this . log ( "_IEModeConversion not overloaded - browser environment not loaded." ) ;
1785+ } ,
1786+
17761787 /**
17771788 Method used to send a request via browser objects to the LRS
17781789
@@ -5522,19 +5533,18 @@ TinCan client library
55225533 "timestamp"
55235534 ] ,
55245535 optionalObjProps = [
5536+ "actor" ,
5537+ "verb" ,
55255538 "result" ,
55265539 "context"
55275540 ] ,
55285541 i ;
55295542
5530- version = version || TinCan . versions ( ) [ 0 ] ;
5531-
55325543 result = {
5533- objectType : this . objectType ,
5534- actor : this . actor . asVersion ( version ) ,
5535- verb : this . verb . asVersion ( version ) ,
5536- object : this . target . asVersion ( version )
5544+ objectType : this . objectType
55375545 } ;
5546+ version = version || TinCan . versions ( ) [ 0 ] ;
5547+
55385548 for ( i = 0 ; i < optionalDirectProps . length ; i += 1 ) {
55395549 if ( this [ optionalDirectProps [ i ] ] !== null ) {
55405550 result [ optionalDirectProps [ i ] ] = this [ optionalDirectProps [ i ] ] ;
@@ -5545,6 +5555,9 @@ TinCan client library
55455555 result [ optionalObjProps [ i ] ] = this [ optionalObjProps [ i ] ] . asVersion ( version ) ;
55465556 }
55475557 }
5558+ if ( this . target !== null ) {
5559+ result . object = this . target . asVersion ( version ) ;
5560+ }
55485561
55495562 return result ;
55505563 }
@@ -6560,6 +6573,7 @@ TinCan client library
65606573 xdrRequest ,
65616574 requestComplete ,
65626575 __delay ,
6576+ __IEModeConversion ,
65636577 env = { } ,
65646578 log = TinCan . prototype . log ;
65656579
@@ -6696,6 +6710,37 @@ TinCan client library
66966710 }
66976711 } ;
66986712
6713+ //
6714+ // Converts an HTTP request cfg of above a set length (//MAX_REQUEST_LENGTH) to a post
6715+ // request cfg, with the original request as the form data.
6716+ //
6717+ __IEModeConversion = function ( fullUrl , headers , pairs , cfg ) {
6718+ var prop ;
6719+
6720+ // 'pairs' already holds the original cfg params, now needs headers and data
6721+ // from the original cfg to add as the form data to the POST request
6722+ for ( prop in headers ) {
6723+ if ( headers . hasOwnProperty ( prop ) ) {
6724+ pairs . push ( prop + "=" + encodeURIComponent ( headers [ prop ] ) ) ;
6725+ }
6726+ }
6727+
6728+ if ( typeof cfg . data !== "undefined" ) {
6729+ pairs . push ( "content=" + encodeURIComponent ( cfg . data ) ) ;
6730+ }
6731+
6732+ // the Authorization and xAPI version headers need to still be present, but
6733+ // the content type must exist and be of type application/x-www-form-urlencoded
6734+ headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
6735+ fullUrl += "?method=" + cfg . method ;
6736+ cfg . method = "POST" ;
6737+ cfg . params = { } ;
6738+ if ( pairs . length > 0 ) {
6739+ cfg . data = pairs . join ( "&" ) ;
6740+ }
6741+ return fullUrl ;
6742+ } ;
6743+
66996744 //
67006745 // one of the two of these is stuffed into the LRS' instance
67016746 // as ._makeRequest
@@ -6712,7 +6757,10 @@ TinCan client library
67126757 finished : false ,
67136758 fakeStatus : null
67146759 } ,
6715- async = typeof cfg . callback !== "undefined"
6760+ async = typeof cfg . callback !== "undefined" ,
6761+ fullRequest = fullUrl ,
6762+ err ,
6763+ MAX_REQUEST_LENGTH = 2048
67166764 ;
67176765 log ( "sendRequest using XMLHttpRequest - async: " + async , LOG_SRC ) ;
67186766
@@ -6721,8 +6769,39 @@ TinCan client library
67216769 pairs . push ( prop + "=" + encodeURIComponent ( cfg . params [ prop ] ) ) ;
67226770 }
67236771 }
6772+
67246773 if ( pairs . length > 0 ) {
6725- fullUrl += "?" + pairs . join ( "&" ) ;
6774+ fullRequest += "?" + pairs . join ( "&" ) ;
6775+ }
6776+
6777+ if ( fullRequest . length >= MAX_REQUEST_LENGTH ) {
6778+ // This may change based upon what content is supported in IE Mode
6779+ if ( typeof headers [ "Content-Type" ] !== "undefined" && headers [ "Content-Type" ] !== "application/json" ) {
6780+ err = new Error ( "Unsupported content type for IE Mode request" ) ;
6781+ if ( typeof cfg . callback !== "undefined" ) {
6782+ cfg . callback ( err , null ) ;
6783+ }
6784+ return {
6785+ err : err ,
6786+ xhr : null
6787+ } ;
6788+ }
6789+
6790+ if ( typeof cfg . method === "undefined" ) {
6791+ err = new Error ( "method must not be undefined for an IE Mode Request conversion" ) ;
6792+ if ( typeof cfg . callback !== "undefined" ) {
6793+ cfg . callback ( err , null ) ;
6794+ }
6795+ return {
6796+ err : err ,
6797+ xhr : null
6798+ } ;
6799+ }
6800+
6801+ fullUrl = __IEModeConversion ( fullUrl , headers , pairs , cfg ) ;
6802+ }
6803+ else {
6804+ fullUrl = fullRequest ;
67266805 }
67276806
67286807 if ( typeof XMLHttpRequest !== "undefined" ) {
@@ -6793,7 +6872,20 @@ TinCan client library
67936872 control = {
67946873 finished : false ,
67956874 fakeStatus : null
6875+ } ,
6876+ err ;
6877+
6878+ if ( typeof headers [ "Content-Type" ] !== "undefined" && headers [ "Content-Type" ] !== "application/json" ) {
6879+ err = new Error ( "Unsupported content type for IE Mode request" ) ;
6880+ if ( cfg . callback ) {
6881+ cfg . callback ( err , null ) ;
6882+ return null ;
6883+ }
6884+ return {
6885+ err : err ,
6886+ xhr : null
67966887 } ;
6888+ }
67976889
67986890 // method has to go on querystring, and nothing else,
67996891 // and the actual method is then always POST
@@ -6892,11 +6984,6 @@ TinCan client library
68926984 return xhr ;
68936985 } ;
68946986
6895- //
6896- // Synchronous xhr handling is accepted in the browser environment
6897- //
6898- TinCan . LRS . syncEnabled = true ;
6899-
69006987 //
69016988 // Override LRS' init method to set up our request handling
69026989 // capabilities
@@ -6918,6 +7005,12 @@ TinCan client library
69187005 //
69197006 this . _makeRequest = nativeRequest ;
69207007
7008+ //
7009+ // overload LRS ._IEModeConversion to be able to test this method,
7010+ // which only applies in a browser setting
7011+ //
7012+ this . _IEModeConversion = __IEModeConversion ;
7013+
69217014 urlParts = this . endpoint . toLowerCase ( ) . match ( / ( [ A - Z a - z ] + : ) \/ \/ ( [ ^ : \/ ] + ) : ? ( \d + ) ? ( \/ .* ) ? $ / ) ;
69227015 if ( urlParts === null ) {
69237016 log ( "[error] LRS invalid: failed to divide URL parts" , LOG_SRC ) ;
@@ -7012,4 +7105,9 @@ TinCan client library
70127105 xhr . open ( "GET" , url , false ) ;
70137106 xhr . send ( null ) ;
70147107 } ;
7108+
7109+ //
7110+ // Synchronous xhr handling is accepted in the browser environment
7111+ //
7112+ TinCan . LRS . syncEnabled = true ;
70157113} ( ) ) ;
0 commit comments