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

Snippets for a multipart request documented with WebTestClient include both the raw body and the parts

Abierto
#1,075 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java, spring

Línea de trabajo

Start by comparing WebTestClientRequestConverter with MockMvcRequestConverter, which builds multipart requests with empty content, and reproduce the bad output with WebTestClientRestDocumentationIntegrationTests.multipart(). Check how CurlRequestSnippet, HttpieRequestSnippet and HttpRequestSnippet handle requests that have parts. Done means the curl, HTTPie and HTTP snippets are usable for WebTestClient multipart requests. The issue asks the maintainer to choose between the two fixes first, so confirm that choice before editing.

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

Descripción

status: waiting-for-triage

When a multipart request is documented with WebTestClient, the curl, HTTPie, and HTTP request snippets can't be used as they are. This can be reproduced with the existing WebTestClientRestDocumentationIntegrationTests.multipart() test, which only checks request-parts.adoc. On 4.0.x, it produces the following snippets (the boundary is shortened here):

curl-request.adoc

$ curl 'https://api.example.com/upload' -i -X POST \
    -H 'Content-Type: multipart/form-data;boundary=abnXMtqL…' \
    -F 'a=alpha;type=text/plain;charset=UTF-8' \
    -F 'b=bravo;type=text/plain;charset=UTF-8' \
    -d '--abnXMtqL…
Content-Disposition: form-data; name="a"
…
--abnXMtqL…--
'

curl refuses to run this command because it contains both -F and -d:

Warning: You can only select one HTTP request method! You asked for both POST
Warning: (-d, --data) and multipart formpost (-F, --form).

The boundary in the -H option also doesn't match the boundary that curl generates for the -F parts.

httpie-request.adoc

$ echo '--abnXMtqL…
…
--abnXMtqL…--
' | http --multipart POST 'https://api.example.com/upload' \
    'a'='alpha' \
    'b'='bravo'

HTTPie doesn't allow a request body from stdin to be combined with request items such as 'a'='alpha'.

http-request.adoc

POST /upload HTTP/1.1
Content-Type: multipart/form-data;boundary=abnXMtqL…; boundary=6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
…

--abnXMtqL…

The Content-Type header has two boundary parameters, and the second one, which is added by the snippet, doesn't match the body.

Cause

MockMvcRequestConverter creates a multipart OperationRequest with empty content and the parts, and the snippets are written with that in mind. WebTestClientRequestConverter creates it with both the raw multipart body (result.getRequestBodyContent()) and the parts that are parsed from it. As a result:

  • CurlRequestSnippet writes -F for each part and also writes -d for the content. It also keeps the request's multipart/form-data Content-Type header.
  • HttpieRequestSnippet pipes the content to stdin and also writes each part as a request item.
  • HttpRequestSnippet writes the content instead of the parts. Because there are parts, it also appends its own boundary to the Content-Type header, even though there's already one.

In main, RestTestClientRequestConverter does the same as WebTestClientRequestConverter.

Possible fixes

I can see two ways to fix this, and I'd like to know which you'd prefer before opening a pull request:

  1. In the converters: when the parts are parsed successfully, WebTestClientRequestConverter (and RestTestClientRequestConverter in main) would create the request with empty content, which is what MockMvcRequestConverter does. This is limited to the converters, and the snippets wouldn't need to change. However, it changes the request that's passed to user preprocessors and snippets. For example, the request-body snippet for a multipart request would be empty, as it already is with MockMvc.
  2. In the snippets: when a request has parts, CurlRequestSnippet would not write -d or the multipart/form-data Content-Type header, HttpieRequestSnippet would not use stdin, and HttpRequestSnippet would write the parts and replace any existing boundary instead of appending another one. The converters wouldn't change, but there are more changes and they're spread across three snippets.

I think the first option is the more consistent one, but I may be missing a reason why the WebTestClient converter keeps the raw content. Please let me know if either of these looks right to you.

Lenguaje dominante
Java
Estrellas
1.2k
Forks
733
Métricas de merge de PR
Sin PR fusionados en 30 d

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 spring-projects/spring-restdocs

Todos los issues de spring-projects/spring-restdocs

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.