Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Headers allow the same entry multiple times with different case

Aperta
#9,238 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
kotlin
Ambito
networking

Direzione di ricerca

Start with the Headers APIs used in the Kotlin example, especially headersOf and toHeaders, and trace how Request.Builder.headers handles names that differ only by case. Add a focused test based on the reproduction; done means the test establishes the intended behavior for repeated case-insensitive header names, which the issue does not specify fully.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

HTTP header names are case-insensitive according to the HTTP specification (RFC 2616, RFC 7230).
So "User-Agent" and "user-agent" should be treated as the same key.

I don't know if this is the intended behavior, but okHttp is sending multiple times the same entry.

import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Headers.Companion.toHeaders
import okhttp3.Headers.Companion.headersOf
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer

private val client = OkHttpClient()
private val server = MockWebServer()

fun main() {
    val defHeaders = mapOf(
        "User-Agent" to "my-user-agent1",
        "Referer" to "my-referer1"
    )
    server.enqueue(MockResponse())

    println("### Headers from MockWebServer ###")
    val myHeaders = mapOf(
        "user-agent" to "my-user-agent2",
        "User-Agent" to "my-user-agent3",
        "referer" to "my-referer2"
    )
    val request1 = Request.Builder()
        .url(server.url("/"))
        .headers((defHeaders + myHeaders).toHeaders())
        .build()

    client.newCall(request1).execute()

    val recordedRequest = server.takeRequest()
    println(recordedRequest.headers)
    server.close()


    println("### Headers from httpbin ###")
    val request2 = Request.Builder()
        .url("https://httpbin.org/get")
        .headers(headersOf(
            "User-Agent", "my-user-agent1",
            "user-agent", "my-user-agent2",
            "User-Agent", "my-user-agent3",
            "Referer", "my-referer1",
            "referer", "my-referer2",
            "Cookie", "key1=va1",
            "cookie", "key2=val2"))
        .build()

    client.newCall(request2).execute().use { response ->
        println(response.body?.string())
    }
}

Terminal output:

### Headers from MockWebServer ###
User-Agent: my-user-agent1
Referer: my-referer1
user-agent: my-user-agent2
Host: localhost:63575
Connection: Keep-Alive
Accept-Encoding: gzip

### Headers from httpbin ###
{
  "args": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Cookie": "key1=va1; key2=val2",
    "Host": "httpbin.org",
    "Referer": "my-referer1,my-referer2",
    "User-Agent": "my-user-agent1,my-user-agent2,my-user-agent3,my-user-agent4",
    "X-Amzn-Trace-Id": "Root=########################"
  },
  "origin": "###.###.###.###",
  "url": "https://httpbin.org/get"
}
Lingua principale
Kotlin
Stelle
47.1k
Fork
9.3k
Merge medio
18h 18m
PR unite (30g)
15

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lysine-dev/okhttp

Tutte le issue di lysine-dev/okhttp

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.