Skip to content

Headers not being assigned #55

@NicosKaralis

Description

@NicosKaralis

After some debugging I've found that the headers setter is calling the getter which calls a dynamic getter and ignores the new values

This declaration

    open var headers : [String: String]? {
        get { return socket.request.allHTTPHeaderFields }
        set {
            for (field, value) in headers ?? [:] {
                socket.request.setValue(value, forHTTPHeaderField: field)
            }
        }
    }

Should be replaced with this

    open var headers : [String: String]? {
        get { return socket.request.allHTTPHeaderFields }
        set {
            for (field, value) in newValue ?? [:] {
                socket.request.setValue(value, forHTTPHeaderField: field)
            }
        }
    }

If you need a test just run this example

  let client: ActionCableClient = {
    let _client = ActionCableClient(url: Defaults.Api.cableURL)
    _client.headers = [
      "Origin": "https://server.example"
    ]
    return _client
  }()
  print(client.headers)
  client.headers = [
    "Origin": "https://server.example",
    "Accept": "accept/json"
  ]
  print(client.headers)
  if !client.isConnected {
    client.connect()
  }

https://github.com/danielrhodes/Swift-ActionCableClient/blob/master/Source/Classes/ActionCableClient.swift#L77

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions