Skip to content

Conversation

@MukjepScarlet
Copy link
Contributor

@MukjepScarlet MukjepScarlet commented Nov 29, 2025

  • Headers + Headers (Java: combine)
  • Headers.Builder += Headers
  • Headers.Builder -= String

@yschimke
Copy link
Collaborator

yschimke commented Jan 1, 2026

I do wonder whether making this easy is hiding the actual complexity.

I feel like merging headers should probably be aware of rules for how to resolve duplicate keys.

Or at least documenting that this is the behaviour, and duplicates should be removed before combine if they would make an invalid request

@yschimke yschimke changed the title feat(Headers): opterator functions Headers operator functions Jan 1, 2026
@MukjepScarlet
Copy link
Contributor Author

Because HTTP headers can be treated as multimap, so I think it's acceptable - or we should create something like addIfAbsent.

@MukjepScarlet
Copy link
Contributor Author

fun Headers.Builder.addIfAbsent(name: String, value: String): Headers.Builder
fun Headers.Builder.addAllIfAbsent(...): Headers.Builder

fun Headers.merge // merge: from Map, withFallback: from typesafe's Config

@swankjesse
Copy link
Collaborator

What's your use case?

@MukjepScarlet
Copy link
Contributor Author

For example

val DEFAULT_UA = headersOf("User-Agent", "Chrome 120...")

Request.Builder().url(...).headers(DEFAULT_UA + headersOf("Authentication", "...")).build()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants