tezvyn:

Add a default header to every URLSession request

Source: interviewintermediate

WHAT IT TESTS: Knowing URLSession is configured, not just used. OUTLINE: Set httpAdditionalHeaders on a URLSessionConfiguration, build the session from it, mention per-request overrides win. RED FLAG: Subclassing URLRequest or mutating every request by hand.

WHAT IT TESTS: Whether you understand that session behavior comes from URLSessionConfiguration, not the shared session. ANSWER OUTLINE: Create a configuration (default or ephemeral), set its httpAdditionalHeaders dictionary with the Authorization entry, then instantiate URLSession with that configuration; every task inherits the headers. Note that a header set directly on a URLRequest overrides the session default, and that sensitive auth is better refreshed dynamically.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Add a default header to every URLSession request · Tezvyn