Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15980] iOS: Replace ASIHttp with NSURLConnection

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-03-18T19:12:14.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 06, 2014 Sprint 06 SDK, Release 3.3.0
ComponentsiOS
Labelsplanning-3.3.0
ReporterIngo Muschenetz
AssigneePedro Enrique
Created2013-12-13T01:06:18.000+0000
Updated2014-06-27T20:27:03.000+0000

Description

We currently use the ASIHttp library to provide network connection support. This library is out of date and deprecated. We aim to replace it with NSUrlConnection to provide better support for mobile app security solutions.

Comments

  1. Stephen Feather 2013-12-13

    yes, yes, and yes again.
  2. Pedro Enrique 2014-01-23

    Initial implementation can be found at https://github.com/pec1985/TiHTTPClient
  3. Pedro Enrique 2014-02-05

    PR: https://github.com/appcelerator/titanium_mobile/pull/5323
  4. Jeff Bonnes 2014-03-05

    The 'Content-Length' header only seems to be available on the 'last' ondatastream event - not on all events as previously occurred. This would be very useful as we display 'downloading XXXKb of XXXXKb' messages for the user. This is using NTLM Authentication over SSL. Sample code and log output for the same file below: Code: fileXhr.ondatastream = function(e) { filelog.debug('xhr.ondatastream fired'); filelog.debug('status=' + fileXhr.status); var totalBytes = fileXhr.getResponseHeader('Content-Length'); filelog.debug('Totalbytes:' + totalBytes); filelog.debug('Progress=' + e.progress); }; Old ASIHttpRequest httpClient [DEBUG] : fileXhr 233ms 130mb ^4mb xhr.ondatastream fired [DEBUG] : fileXhr 234ms 130mb ^4mb status=401 [DEBUG] : fileXhr 234ms 130mb ^4mb Totalbytes:1293 [DEBUG] : fileXhr 234ms 130mb ^4mb Progress=1 [DEBUG] : fileXhr 734ms 133mb ^1mb xhr.ondatastream fired [DEBUG] : fileXhr 735ms 133mb ^1mb status=200 [DEBUG] : fileXhr 735ms 133mb ^1mb Totalbytes:1571627 [DEBUG] : fileXhr 735ms 133mb ^1mb Progress=0.07360270619392395 [DEBUG] : fileXhr 984ms 133mb ^0mb xhr.ondatastream fired [DEBUG] : fileXhr 984ms 133mb ^0mb status=200 [DEBUG] : fileXhr 984ms 133mb ^0mb Totalbytes:1571627 [DEBUG] : fileXhr 984ms 133mb ^0mb Progress=0.3759238123893738 [DEBUG] : fileXhr 1234ms 114mb ^20mb xhr.ondatastream fired [DEBUG] : fileXhr 1235ms 114mb ^20mb status=200 [DEBUG] : fileXhr 1235ms 114mb ^20mb Totalbytes:1571627 [DEBUG] : fileXhr 1235ms 114mb ^20mb Progress=0.6678200364112854 [DEBUG] : fileXhr 1485ms 86mb ^47mb xhr.ondatastream fired [DEBUG] : fileXhr 1485ms 86mb ^47mb status=200 [DEBUG] : fileXhr 1485ms 86mb ^47mb Totalbytes:1571627 [DEBUG] : fileXhr 1486ms 86mb ^47mb Progress=0.9909908771514893 [DEBUG] : fileXhr 1490ms 85mb ^49mb xhr.ondatastream fired [DEBUG] : fileXhr 1490ms 85mb ^49mb status=200 [DEBUG] : fileXhr 1490ms 85mb ^49mb Totalbytes:1571627 [DEBUG] : fileXhr 1490ms 85mb ^49mb Progress=1.00082266330719 [DEBUG] : fileXhr 1493ms 81mb ^53mb starting onload New NSUrlConnection httpClient [DEBUG] : fileXhr 118ms 118mb ^-8mb xhr.ondatastream fired [DEBUG] : fileXhr 118ms 118mb ^-8mb status=0 [DEBUG] : fileXhr 118ms 118mb ^-8mb Totalbytes:undefined [DEBUG] : fileXhr 118ms 118mb ^-8mb Progress=0.010242888703942299 [DEBUG] : fileXhr 150ms 118mb ^-8mb xhr.ondatastream fired [DEBUG] : fileXhr 150ms 118mb ^-8mb status=0 [DEBUG] : fileXhr 150ms 118mb ^-8mb Totalbytes:undefined [DEBUG] : fileXhr 150ms 118mb ^-8mb Progress=0.05194234848022461 [DEBUG] : fileXhr 182ms 118mb ^-8mb xhr.ondatastream fired [DEBUG] : fileXhr 182ms 118mb ^-8mb status=0 [DEBUG] : fileXhr 182ms 118mb ^-8mb Totalbytes:undefined [DEBUG] : fileXhr 182ms 118mb ^-8mb Progress=0.09364181011915207 [DEBUG] : fileXhr 215ms 118mb ^-8mb xhr.ondatastream fired [DEBUG] : fileXhr 215ms 118mb ^-8mb status=0 [DEBUG] : fileXhr 215ms 118mb ^-8mb Totalbytes:undefined [DEBUG] : fileXhr 215ms 118mb ^-8mb Progress=0.13534127175807953 ... etc ... [DEBUG] : fileXhr 870ms 118mb ^-8mb xhr.ondatastream fired [DEBUG] : fileXhr 870ms 118mb ^-8mb status=0 [DEBUG] : fileXhr 870ms 118mb ^-8mb Totalbytes:undefined [DEBUG] : fileXhr 870ms 118mb ^-8mb Progress=0.896356463432312 [DEBUG] : fileXhr 905ms 118mb ^-8mb xhr.ondatastream fired [DEBUG] : fileXhr 905ms 118mb ^-8mb status=0 [DEBUG] : fileXhr 905ms 118mb ^-8mb Totalbytes:undefined [DEBUG] : fileXhr 905ms 118mb ^-8mb Progress=0.9380559325218201 [DEBUG] : fileXhr 935ms 116mb ^-6mb xhr.ondatastream fired [DEBUG] : fileXhr 935ms 116mb ^-6mb status=0 [DEBUG] : fileXhr 935ms 116mb ^-6mb Totalbytes:undefined [DEBUG] : fileXhr 935ms 116mb ^-6mb Progress=0.9797554016113281 [DEBUG] : fileXhr 951ms 116mb ^-6mb xhr.ondatastream fired [DEBUG] : fileXhr 951ms 116mb ^-6mb status=200 [DEBUG] : fileXhr 951ms 116mb ^-6mb Totalbytes:1571627 [DEBUG] : fileXhr 951ms 116mb ^-6mb Progress=1
  5. Pedro Enrique 2014-03-05

  6. Jeff Bonnes 2014-03-06

    Got another one for you. When POSTing files, the filename in Content-Disposition and the Content-Type are not being set properly. See the requests for the old and new below (full requests follow) Old ASIHttpRequest httpClient:
       Content-Disposition: form-data; name="files"; filename="*residential-tenancy-agreement.PDF*"
       Content-Type: *application/pdf*
       
    New NSUrlConnection httpClient:
       Content-Disposition: form-data; name="files"; filename="*file0*"
       Content-Type: *application/octet-stream*
       
    ---- Full Headers: Old ASIHttpRequest httpClient:
       POST /default.aspx?a=anr&t=6&u=335602 HTTP/1.1
       Host: grundy01.kapish.local:443
       X-Titanium-Id: 3fe5003f-1574-4300-8e76-8ef1dd10ecf5
       X-Requested-With: XMLHttpRequest
       Proxy-Connection: close
       Content-Type: multipart/form-data; charset=utf-8; boundary=0xKhTmLbOuNdArY-D28F5749-96F6-4114-8778-A54A880DDD56
       Accept-Encoding: gzip
       Content-Length: 1571868
       Cookie: ASP.NET_SessionId=1lvlt34iui0xbenq0ihiuxfd
       Connection: close
       User-Agent: Appcelerator Titanium/3.3.0.v20140304134105 (iPad Simulator/7.0.3; iPhone OS; en_US;)
       
       --0xKhTmLbOuNdArY-D28F5749-96F6-4114-8778-A54A880DDD56
       Content-Disposition: form-data; name="files"; filename="residential-tenancy-agreement.PDF"
       Content-Type: application/pdf
       
       %PDF-1.6
       %‚„œ” etc...
       
    New NSUrlConnection httpClient:
       POST /default.aspx?a=anr&t=6&u=335602 HTTP/1.1
       Host: grundy01.kapish.local:443
       Accept-Language: en-us
       User-Agent: Appcelerator Titanium/3.3.0.v20140304134105 (iPad Simulator/7.0.3; iPhone OS; en_US;)
       Proxy-Connection: keep-alive
       X-Requested-With: XMLHttpRequest
       Accept: */*
       Content-Type: multipart/form-data; charset=utf-8; boundary=0xTibOuNdArY_1394075012
       Connection: keep-alive
       Cookie: ASP.NET_SessionId=2g4bbjjehrc52dds1h4iu4cb
       Authorization: Digest username="jbonnes", realm="Digest", nonce="+Upgraded+v1779ef9b7eb16488297431a0b2983f3d4dee2999de838cf01fc2b41b649d8fa0e50337c8f9175eb389c113e8639c2dfcbac9f094388418f24", uri="/default.aspx?a=anr&t=6&u=335602", response="9bd9ff848af6c3b5613693c4b08fccb2", algorithm="MD5-sess", cnonce="df4afa0d131fa3e18a2c5144c5270ffd", nc=00000006, qop="auth"
       X-Titanium-Id: 3fe5003f-1574-4300-8e76-8ef1dd10ecf5
       Content-Length: 1571791
       Accept-Encoding: gzip, deflate
       
       --0xTibOuNdArY_1394075012
       Content-Disposition: form-data; name="files"; filename="file0"
       Content-Type: application/octet-stream
       
       %PDF-1.6
       %‚„œ” etc....
       
  7. Pedro Enrique 2014-03-06

  8. Fokke Zandbergen 2014-03-07

    Tested with several apps and found no problems.
  9. Eric Merriman 2014-06-06

    [~fokke] Thanks Fokke. We do appreciate the feedback.
  10. Eric Merriman 2014-06-13

    Primary testing complete. Will continue to evaluate any upcoming changes.
  11. Eric Merriman 2014-06-27

    Testing has not uncovered any issues with feature implementation.

JSON Source