Setting HTTP Headers

You can set HTTP headers for the iOS Hybrid Web Container to include authentication tokens.

There are three sample methods showing how to do this in the iOS Hybrid Web Container template source code, which include:
  • setHttpHeaders – use this method to set the authentication tokens. The tokens you set are used from then on until setHttpHeaders is called again.
  • onWorkflowTokenError – use this method to call setHttpHeaders to put the authentication tokens back in a good state, if, for example, they have expired.
  • onHTTPError – use this method to handle HTTP errors.

All code areas associated with HTTP header customization are annotated with IOS_CUSTOMIZATION_POINT_HTTPHEADERS.

  1. Open the CustomizationHelper.m file, which is located in WorkFlow\Classes.
  2. Locate the setHttpHeaders method, and uncomment its contents.
    The stub code that is provided shows an example of how to add headers and cookies. You simply need to replace the header and cookie assignments with your own. The setHttpHeaders function is already called in the startEngine function just before the client engine starts, so you need to provide the implementation of setHttpHeaders.
  3. CustomizationHelper.m also includes stub implementations of onWorkflowTokenError and onHTTPError that you can implement.
    The onWorkflowTokenError method is called when Workflow token authentication failure occurs, so it is a good idea to use this callback as an opportunity to refresh the HTTP headers again. A common way to do this is to maintain member variables that contain the values for the headers you want to set. Implement the setHttpHeaders function to use the values in those member variables when it sets the headers, then, in onWorkflowTokenError, you can update the member variables with the new header values, and then call setHttpHeaders again, for example:
    [[CustomizationHelper getInstance] setHttpHeaders];
  4. If you have custom code to run when an HTTP error occurs, add it to the onHTTPError function.
    This method is called any time there is an HTTP error. You can use this to inform the user of errors, or log errors, or perform other custom steps in response to particular error codes.