Moya: iOS 12 not setting custom headers with TargetType headers

Created on 8 Oct 2018  路  1Comment  路  Source: Moya/Moya

I'm using Moya 11.0.2 for iOS 12 app but it's not setting the headers value for the request. The request only contains the default HTTP headers, not the custom ones.

Still not working for Moya 12.0.0.beta.1.

It works well on iOS 11.

extension OwnService : TargetType {
    var headers: [String : String]? {
        switch self {
        case .checkKey(let params):
            return ["Content-Type": "application/json", "custom-key" : params.key]
        }
    }

    var method: Moya.Method {
        switch self {
        case .checkKey:
            return .post
        }
    }

    var task: Task {
        switch self {
        case .checkKey:
            return .requestPlain
        }
    }
}

let provider = MoyaProvider<OwnService >(plugins: [NetworkLoggerPlugin(verbose: true, responseDataFormatter: ServerProxyConstants.JSONResponseDataFormatter)])

provider.request(.checkKey(key: "custom key")) { (result) in
    // Custom code here 
}
bug?

Most helpful comment

Sorry, the problem was that my custom key ended with a \n character, so the provider excluded it.

>All comments

Sorry, the problem was that my custom key ended with a \n character, so the provider excluded it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hamada147 picture hamada147  路  3Comments

JoeFerrucci picture JoeFerrucci  路  3Comments

pedrovereza picture pedrovereza  路  3Comments

dimpiax picture dimpiax  路  3Comments

holysin picture holysin  路  3Comments