Restkit Authorization Header disappears

247 views Asked by At

I already searched everywhere and this issue that should have been trivial is taking longer than I wanted therefore I am reaching you for help.

I am using swift and integrated restkit using cocoapods.

Despite, as you can see the screenshots/log, the header is fine however the outgoing http packet is not consistent.

AppDelegate:

RKlcl_configure_by_name("RestKit/Network", RKlcl_vTrace.value);
RKlcl_configure_by_name("RestKit/ObjectMapping", RKlcl_vTrace.value);

ObjectManagerCode:

let objectManager: RKObjectManager = RKObjectManager(baseURL: NSURL(string: Endpoints.BaseUrl.toString()))
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

let username = "TestUser"
let password = "password"

objectManager.HTTPClient.setAuthorizationHeaderWithUsername(username, password: password)
objectManager.HTTPClient.setDefaultHeader("whatIWantForChristmas", value: "You")
objectManager.HTTPClient.allowsInvalidSSLCertificate = true

Request:

var requestUrl = cds.objectManager!.requestWithObject(
        nil,
        method: RKRequestMethod.GET,
        path: endpoint.path,
        parameters: endpoint.parameters())



cds.objectManager!.getObjectsAtPath(
        endpoint.path,
        parameters: endpoint.parameters(),
        success:
        {
            (RKObjectRequestOperation, RKMappingResult) -> Void in

            println(RKObjectRequestOperation.description)
            Logger.Info("Success");
        },
        failure: {
            (RKObjectRequestOperation, error) -> Void in

            Logger.Error("Error: \(error.description)")
            println(RKObjectRequestOperation.HTTPRequestOperation.description)

        })

Log:

T restkit.network:RKObjectRequestOperation.m:178 GET 'http://website/api?format=json':

request.headers={
    Accept = "application/json";
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    Authorization = "Basic VGVzdFVzZXI6cGFzc3dvcmQ=";
    "User-Agent" = "malaria-ios/1 (iPhone Simulator; iOS 8.3; Scale/2.00)";
    whatIWantForChristmas = You;
}

...

E restkit.network:RKObjectRequestOperation.m:576 Object request
failed:Underlying HTTP request operation failed with error: 
Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 403" 
UserInfo=0x7ff54ae4f690 {NSLocalizedRecoverySuggestion={"detail":"Authentication credentials were not provided."}

What I figured out: I can send anything in the header as long as it isn't "Authorization", if I change to "Authorization2", ok. The header "WhatIWantForChristmas" is also there. The authorization isn't despite being present in the log! It seems that the underlying software filters.

Out of paranoia I tried turning off firewall, cleaning project, reseting iOS simulator and nada. The application I used to see the HTTP packets is Charles.

What am I doing wrong?

Url for the screenshot pf Charles: http://s7.postimg.org/pfwn7kyq2/Screen_Shot_2015_06_20_at_21.jpg

0

There are 0 answers