Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Evaluates Java HTTP Client support for HTML form submissions (application/x-www-form-urlencoded) and multipart/form-data requests including file uploads.

Changes

Test Suites

  • JavaHttpClientFormsTest - 4 tests demonstrating no built-in form API, manual URL encoding required
  • JavaHttpClientMultipartTest - 5 tests demonstrating no built-in multipart API, manual boundary/header construction required

Test Infrastructure

  • NettyFormsServer - Handles POST requests, parses form-urlencoded and multipart data for validation

Documentation

  • FORMS_AND_MULTIPART.md - Analysis of missing APIs, comparison with Apache HttpClient/OkHttp, manual implementation requirements
  • README.md - Updated with new test scenarios

Key Findings

Java HTTP Client provides no convenience APIs for forms or multipart. Developers must manually:

// Forms: Manual URL encoding required
String formData = data.entrySet().stream()
    .map(e -> URLEncoder.encode(e.getKey(), UTF_8) + "=" + 
              URLEncoder.encode(e.getValue(), UTF_8))
    .collect(Collectors.joining("&"));

HttpRequest.newBuilder()
    .header("Content-Type", "application/x-www-form-urlencoded")
    .POST(HttpRequest.BodyPublishers.ofString(formData))
    .build();

// Multipart: Manual boundary generation and part construction required
String boundary = "----WebKitFormBoundary" + System.currentTimeMillis();
byte[] body = buildMultipartBody(boundary, fields, files); // Complex manual construction

HttpRequest.newBuilder()
    .header("Content-Type", "multipart/form-data; boundary=" + boundary)
    .POST(HttpRequest.BodyPublishers.ofByteArray(body))
    .build();

Compare with other clients (Apache HttpClient MultipartEntityBuilder, OkHttp MultipartBody.Builder()).

Test Results: 9 tests added, all pass. No security vulnerabilities (CodeQL).

Original prompt

This section details on the original issue you should resolve

<issue_title>Evaluation of Forms an Multiparts</issue_title>
<issue_description>## Forms

Convince Support for posting of form data to the server.

One can always do this if you’re willing to build up the request from scratch yourself, so what we’re really talking about here is whether a specific API is provided.

Multipart request and file upload

Support for sending multipart requests to the server, as with forms, we’re interested in whether the client provides an API specifically for this and how it can be improved</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 14, 2025 16:28
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copilot AI changed the title [WIP] Evaluate support for forms and multipart requests Add Forms and Multipart evaluation tests and documentation Nov 14, 2025
Copilot AI requested a review from laeubi November 14, 2025 16:36
Copilot finished work on behalf of laeubi November 14, 2025 16:36
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.

Evaluation of Forms an Multiparts

2 participants