Stirling-PDF/app
Ludy 23f872823d
fix(pipeline): avoid bad multipart by letting RestTemplate set boundary (#5522)
# Description of Changes

- **What was changed**
- Updated `PipelineProcessor#sendWebRequest(...)` to stop forcing
`Content-Type: multipart/form-data` and to stop manually writing the
multipart body via `FormHttpMessageConverter`.
- Switched to `RestTemplate#httpEntityCallback(...)` (`RequestCallback`)
so Spring’s configured message converters handle multipart serialization
(including boundary generation) correctly.
- Made `X-API-KEY` header conditional (only added when
non-null/non-empty).
- Added a unit test (`sendWebRequestDoesNotForceContentType`) to ensure
`Content-Type` is not explicitly set on the outgoing request headers and
that the request succeeds end-to-end using mocked `RestTemplate`
behavior.

- **Why the change was made**
- The server-side error `org.eclipse.jetty.http.BadMessageException:
400: bad multipart` with `EOFException: unexpected EOF` indicates the
multipart request can be malformed (commonly due to
boundary/content-type mismatches or prematurely terminated streams).
Manually setting the multipart content type and writing the body can
bypass Spring’s normal boundary handling and lead to invalid multipart
payloads. Letting `RestTemplate` handle it ensures correct formatting.

---

This pull request updates how multipart web requests are sent in the
pipeline processor to avoid forcing the `Content-Type` header for
multipart requests, allowing the message converter to set it
automatically. It also adds a new test to ensure this behavior. The main
changes are focused on improving multipart request handling and
increasing test coverage.

**Multipart request handling improvements:**

* Refactored `PipelineProcessor.runPipelineAgainstFiles` to avoid
explicitly setting the `Content-Type` header to `multipart/form-data`,
letting the message converter set the appropriate boundary and content
type instead. This helps prevent issues with incorrect boundaries and
improves compatibility with multipart requests.
* Updated imports in `PipelineProcessor.java` to remove unused
`FormHttpMessageConverter` and add `RequestCallback`.

**Testing enhancements:**

* Added a new test `sendWebRequestDoesNotForceContentType` in
`PipelineProcessorTest.java` to verify that the `Content-Type` header is
not set explicitly and is left for the message converter to handle. This
test uses mocking to simulate the request and response flow.
* Added necessary imports in `PipelineProcessorTest.java` to support new
test logic and mocking.
[[1]](diffhunk://#diff-1a45e7b37023bd3a9580ab24d7025bb359cb8891c486111d372c0557f817b3edR7-R8)
[[2]](diffhunk://#diff-1a45e7b37023bd3a9580ab24d7025bb359cb8891c486111d372c0557f817b3edR18-R27)

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
2026-01-21 22:00:59 +00:00
..
common refactor: remove legacy Thymeleaf web UI controllers and templates (#5406) 2026-01-21 21:58:29 +00:00
core fix(pipeline): avoid bad multipart by letting RestTemplate set boundary (#5522) 2026-01-21 22:00:59 +00:00
proprietary refactor: remove legacy Thymeleaf web UI controllers and templates (#5406) 2026-01-21 21:58:29 +00:00
allowed-licenses.json [V2] feat(security): add PDF standards verification feature using veraPDF (#4874) 2025-12-23 22:29:30 +00:00