Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24329] iOS: setting additional request header disallows POST form requests

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-02-09T14:22:32.000+0000
Affected Version/sRelease 6.1.0
Fix Version/sRelease 6.1.0
ComponentsiOS
Labelsios, qe-6.1.0, regression
ReporterChristoph Eck
AssigneeHans Knöchel
Created2017-01-19T13:44:51.000+0000
Updated2017-02-15T13:26:01.000+0000

Description

*Problem* Setting additional request headers disallows POST form requests to the same page. The 'load' event is not fired. _actual behavior_

click on 'open local page'

in the log is shown 'beforeload' and 'load' event

click on Submit button

in the log is shown 'beforeload'

_expected behavior_

click on 'open local page'

in the log is shown 'beforeload' and 'load' event

click on Submit button

in the log is shown 'beforeload' and 'load' event

*Test case* file index.js {noformat} var win = Ti.UI.createWindow({ backgroundColor:'white' }); var buttonGoogle = Ti.UI.createButton({ title:'Open local page', top:'20%', height:'30%', left:'10%', right:'10%' }); buttonGoogle.addEventListener('click', function(){ Ti.Network.removeAllHTTPCookies( ); var webView = Ti.UI.createWebView(); webView.setBasicAuthentication("username", "password"); var requestHeaders = { "Accept-Language": "en", "X-Agent" : "Mobile" }; webView.setRequestHeaders(requestHeaders); webView.addEventListener('load', function(){ Ti.API.info('load: ' + webView.url); }); webView.addEventListener('beforeload', function(){ Ti.API.info('beforeload: ' + webView.url); }); webView.addEventListener('error', function(){ Ti.API.info('error: ' + webView.url); }); win.add(webView); var button = Ti.UI.createButton({ title:'Close', right:0, bottom:0, height:'10%', width:'20%' }); button.addEventListener('click', function(){ win.remove(webView); }); webView.add(button); var url = "web/index.html"; webView.setUrl(url); }); win.add(buttonGoogle); win.open(); {noformat} file app/assets/web/index.html {noformat}
{noformat} *Log* _actual behavior_ {noformat} [INFO] : beforeload: web/index.html [INFO] : load: web/index.html [INFO] : beforeload: web/index.html {noformat} _expected behavior_ {noformat} [INFO] : beforeload: web/index.html [INFO] : load: web/index.html [INFO] : beforeload: web/index.html [INFO] : load: web/index.html {noformat}

Attachments

FileDateSize
index.html2017-01-19T13:42:06.000+0000305
index.js2017-01-19T14:18:15.000+00001296

Comments

  1. Hans Knöchel 2017-01-19

    Hey Chirs (you should change your username to have something linkable :-), I see you tested with master (6.1.0), did this not happen in earlier versions of the SDK? If not, in which one did it work? I have a suspicion.
  2. Christoph Eck 2017-01-19

    Hi Hans The additional request header setting is new in Ti SDK 6.1.0. I am using request headers and catch load and beforeload events. The issue only appears with additional request headers. I have already a solution for this. Give me a second to create a pull request. To your questions "did this not happen in earlier versions of the SDK?" No, because of the new additional request header feature.
  3. Hans Knöchel 2017-01-19

    Gotcha! I was just able to reproduce this issue an moved it to Engineering for further investigation. Thank you! *EDIT*: What I observed so far is, that the headers are different from loading the native webview request and the html-based request. - webview-request-headers: Upgrade-Insecure-Requests, X-Titanium-Local-Id, Authorization - html-submit-request-headers: Origin, Content-Type So after adding your 2 request headers, they are added to the list. For some reason, iOS then decides to not allow the request anymore. This will require more investigation. *EDIT 2*: Fixed it, the issue was that there is an internal flag that checks for the URL status. This needs to be reset before loading the updated request with the new headers. The fix is ready and will come asap.
  4. Christoph Eck 2017-01-19

    -I could see that the problem happens also on Android.-
  5. Hans Knöchel 2017-01-19

    Mhh, on Android we only pass it to the native methods, so if it doesn't fire from there, we can't really intercept it.
  6. Christoph Eck 2017-01-19

    I tried it with a different test setup and it works on Android. So my first try and guess was wrong. Here are the test files: *index.js* {noformat} var win = Ti.UI.createWindow({ backgroundColor:'white' }); var buttonGoogle = Ti.UI.createButton({ title:'Open local page', top:'200', height:Ti.UI.SIZE, left:'30', }); buttonGoogle.addEventListener('click', function() { var ldf = Ti.Platform.displayCaps.logicalDensityFactor; var webView = Ti.UI.createWebView({ height: Math.floor(Ti.Platform.displayCaps.platformHeight / ldf), width: Math.floor(Ti.Platform.displayCaps.platformWidth / ldf), backgroundColor: "white", }); webView.setBasicAuthentication("username", "password"); var requestHeaders = { "Accept-Language": "en", "X-Agent" : "Mobile" }; webView.setRequestHeaders(requestHeaders); webView.addEventListener('load', function(){ Ti.API.info('load: ' + webView.url); }); webView.addEventListener('beforeload', function(){ Ti.API.info('beforeload: ' + webView.url); }); webView.addEventListener('error', function(){ Ti.API.info('error: ' + webView.url); }); win.add(webView); var button = Ti.UI.createButton({ title:'Close', top:25, bottom:0, height:Ti.UI.SIZE, width:100 }); button.addEventListener('click', function(){ win.remove(webView); }); webView.add(button); var url = "/web/index.html"; webView.setUrl(url); }); win.add(buttonGoogle); win.open(); {noformat} *assets/web/index.html* {noformat}
{noformat}
  • Harry Bryant 2017-02-15

    Verified as fixed, ran an app with the provided demo code firstly with an affected 6.1.X build to confirm that the error is reproducible in my environment. Subsequently built the app with a 6.1.X build containing PR #8765 and was able to receive the expected behaviour. Tested with: iPhone 7 (10.2) Device & Simulator iPhone 6S (9.3) Simulator iPhone 5S (9.3) Device Mac OS Sierra (10.12.2) Ti SDK: 6.1.0.v20170213134957 Appc Studio: 4.8.1.201701192045 Appc NPM: 4.2.9-1 App CLI: 6.1.0 Xcode 8.2.1 Node v4.4.7 *Closing ticket.*
  • JSON Source