Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17467] iOS/Android: Expose request-headers for WebView

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2016-08-29T21:34:59.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sRelease 6.1.0
ComponentsAndroid, iOS
LabelsTCSupport
ReporterTomasz Krzywda
AssigneeHans Knöchel
Created2014-07-30T10:37:07.000+0000
Updated2017-02-11T13:39:01.000+0000

Description

Steps to Reproduce

The concept is simple, to let user add custom headers to web view requests. Example:
var webView = Ti.UI.createWebView();
webView.setHeaders({header1: 'Hello', header2: 'World'});
or directly during creation:
var webView = Ti.UI.createWebView({
    headers: {header1: 'Hello', header2: 'World'}
});

Actual Result

No acces to web view headers, except for user-agent.

Expected Result

Can add custom header to request.

Attachments

FileDateSize
IMG_0486.JPG2016-11-21T18:54:00.000+00002409773

Comments

  1. Mauro Parra-Miranda 2014-08-07

    Thanks for your report. The priority will be set by the Platform team.
  2. Nuno Costa 2015-10-23

    Any update? There is any possibility to pass a custom referrer URL, like: https//:app.foo.com ? Thanks
  3. Tomasz Krzywda 2015-10-23

    Sorry, unfortunately I am not working on that project anymore and I can't set up test env.
  4. Michael Gangolf 2016-01-24

    Started a fork: https://github.com/m1ga/titanium_mobile/commit/9555725b2fe532bd7f7c46a59fc911da9df6b6da you can use it like this:
       $.www.setHeader({
               "User-Blub": "blablabla",
               "Referer": "http://www.test.de"
           });
       
    still work in progress but my first tests are working
  5. Manojkumar Murugesan 2016-04-03

    +1 for this feature. https://github.com/mano-mykingdom/titanium_mobile/commit/091149c94550acaac8acd1241db558fa3db2ce4b
  6. Michael Gangolf 2016-08-15

    Cleaned Android PR version: https://github.com/appcelerator/titanium_mobile/pull/8230
  7. Hans Knöchel 2016-08-17

    Parity-PR for iOS: https://github.com/appcelerator/titanium_mobile/pull/8239
  8. Hans Knöchel 2016-08-17

    Assigning the review to Ash for Android. After merged, please re-assign the reviewer to [~apetkov] to review and merge the iOS-part. I will update the docs when everything is tested and merged. Demo for QE (should work cross-platform, [~michael] to confirm):
       var webView = Ti.UI.createWebView({
       	url: "https://httpbin.org/headers",
       	requestHeaders: {
       		"User-Blub": "blablabla",
       		"Referer": "http://www.test.de",
       		"something": "string1",
       		"other": "string2"
       	}
       });
       
       /* Alternatively, use this setter
       webView.setRequestHeaders({
       	"User-Blub": "blablabla",
       	"Referer": "http://www.test.de",
       	"something": "string1",
       	"other": "string2"
       });*/
       
       var win = Ti.UI.createWindow();
       var btn = Ti.UI.createButton({
       	title : "Reload"
       });
       
       btn.addEventListener("click", function() {
       	webView.reload();
       });
       
       win.add(webView);
       win.add(btn);
       win.open();
       
       Ti.API.warn(webView.requestHeaders);
       Ti.API.warn(webView.getRequestHeaders());
       Ti.API.warn(Object.keys(webView.requestHeaders).length);
       
  9. Michael Gangolf 2016-08-19

  10. Ashraf Abu 2016-08-29

    Android PR https://github.com/appcelerator/titanium_mobile/pull/8230 merged. [~hansknoechel]
  11. Hans Knöchel 2016-08-29

    [~apetkov] to review the iOS-PR.
  12. Abir Mukherjee 2016-11-21

    [~hansknoechel]Attached is a screenshot on a device. Is this what is expected to be seen? !IMG_0486.JPG|thumbnail!
  13. Hans Knöchel 2016-11-21

    Yes
  14. Abir Mukherjee 2016-11-22

    Thanks, Hans. So I did verify that the feature works as expected with the following environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.0.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.1.0.v20161122053743 Appcelerator Studio, build: 4.8.0.201611121409 Xcode 8.1 GM iOS Device: iOS 10.1.1 Android Device: 6.0.1 I tried the extended demo code provided by Michael G, and tried all three test scenarios. The following tests performed as expected on both the Android and iOS devices: 1. requestHeaders property are set during creation 2. custom headers survive a reload (press button reload, output stays the same) 3. header can be changed with change header + reload to display the output
  15. Christoph Eck 2017-02-09

    Hi I had several issues with the iOS implementation.

    *A second POST request to the same address*: Because of the second loadUrlRequest call it could not send a second POST request. I mean the call

        [self loadURLRequest:newRequest];
        
    in the implementation. I made a fix for that see TIMOB-24329 But still this fix does not solve all request cycles propberly which can happen in a WebView itself.

    *Own Request-Headers and Basic-Authentication-Headers*: I had a strange behaviour with including Basic Authentication and my own Request-Headers. It was difficult to determine the error but in the end I removed the second [self loadURLRequest:newRequest]; by setting the headers and Basic Authentication in the loadURLRequest itself. See at https://github.com/chreck/titanium_mobile/commit/4d67118bebe74e9c9f008df1e40327ffb44feb8e

    Best regards Christoph
  16. Christoph Eck 2017-02-10

    Hi I made a Jira about this issue. AC-4786 Best regards Christoph

JSON Source