Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

HttpClient removes Content-Length and causes 411

Abierto
#656 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
swift
Área
networking

Línea de trabajo

Comienza en RequestValidation.swift, en setTransportFraming, donde se elimina Content-Length para las solicitudes GET de longitud cero. Sigue cómo se configuran los encabezados de la solicitud y determina dónde podría exponerse una sobrescritura. La tarea estará terminada cuando los llamadores puedan forzar un Content-Length apropiado para las solicitudes GET y la solicitud resultante funcione con servidores que devuelven 411 cuando no está presente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

When attempting to make GET calls with Django based server, I'm getting a 411 Length Required. Looking at the code in RequestValidation.swift, it is removing Content-Length from headers for GET calls. This may be according to specs but it appears that some servers still require this (probably set to 0). There should be some way to override this behavior or to cause it to force Content-Length to appear in the headers.

I have worked around this by implementing my own networking code using URLSession and the calls do work since I can control the headers exactly.

For reference, the code that is causing the problem is here:

    private mutating func setTransportFraming(
        method: HTTPMethod,
        bodyLength: RequestBodyLength
    ) {
        self.remove(name: "Content-Length")
        self.remove(name: "Transfer-Encoding")

        switch bodyLength {
        case .known(0):
            // if we don't have a body we might not need to send the Content-Length field
            // https://tools.ietf.org/html/rfc7230#section-3.3.2
            switch method {
            case .GET, .HEAD, .DELETE, .CONNECT, .TRACE:
                // A user agent SHOULD NOT send a Content-Length header field when the request
                // message does not contain a payload body and the method semantics do not
                // anticipate such a body.
                break
            default:
                // A user agent SHOULD send a Content-Length in a request message when
                // no Transfer-Encoding is sent and the request method defines a meaning
                // for an enclosed payload body.
                self.add(name: "Content-Length", value: "0")
            }
        case .known(let length):
            self.add(name: "Content-Length", value: String(length))
        case .unknown:
            self.add(name: "Transfer-Encoding", value: "chunked")
        }
    }
Lenguaje dominante
Swift
Estrellas
1.1k
Forks
156
Merge medio
1 h 54 min
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de swift-server/async-http-client

Todos los issues de swift-server/async-http-client

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.