1

I have checkout spring-boot-http-3-jetty and run. It's working as expected[http-3(h3) from 2nd request] furthermore, I want to test it with POST request with body so, I have added the following thymeleaf dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

To handle form request added Controller

package com.example.demo;

import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.ServletRequest;

@Controller
public class UploadController {
    @GetMapping("/upload")
    public String displayUploadForm(ServletRequest request, Model model) throws IOException {
        System.out.println("displayUploadForm:" + request.getProtocol());
        model.addAttribute("message", "hello from upload controller...");
        return "uploadForm";
    }

    @PostMapping("/handleUpload")
    public String handleFileUpload(@RequestParam("file") MultipartFile file, Model model) {
        model.addAttribute("message", "You successfully uploaded " + file.getOriginalFilename() + "!");
        return "uploadForm";
    }
}

Added thymeleaf template

<html>
<body>
    <div th:if="${message}">
        <h2 th:text="${message}"/>
    </div>

    <div>
        <form method="POST" enctype="multipart/form-data" action="/handleUpload">
            <table>
                <tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr>
                <tr><td></td><td><input type="submit" value="Upload" /></td></tr>
            </table>
        </form>
    </div>
</body>
</html>

While hitting https://demo.local:9002/upload It shows form like and getting response header

alt-svc h3=":9002"; ma=86400; persist=1

upload form

But after submitting form getting below error Secure Connection Failed

I have import certificate in firefox. Also with RestController GET request working with http-3 after initial request served with (http-2 & response header alt-svc h3=":9002"; ma=86400; persist=1

also notice sometime its working http-2 for consecutive request.

Note:

  1. checking with latest firefox
  2. java version 19 on windows os

Its there any other config need to check to work with http-3(h3)?

Thanks in advance :-)

2
  • Have you tried sending the request via something like curL or Postman to see if there's any difference in behaviour? With browsers, CORS can be a problem for testing these things Commented Feb 14, 2024 at 11:36
  • same api you can check through postman and let us know what error are you getting Commented Feb 18, 2024 at 10:45

1 Answer 1

2

Your code is working fine for me. I'm using latest Firefox on MacOS.

The repository that you took specifically talks about setting up the project on MacOS not on Windows.

Note: For Windows, HTTP/3 is only supported on Windows Server 2022 & Windows 11. It's not enabled by default.

Important: Follow this SO Answer - How Do You Enable HTTP/3 on IIS? to enable HTTP/3 on Windows and also to make your codebase work.


I'm providing the steps how I followed for MacOS.

  • After I checkout the code, I executed the command - brew install --HEAD -s curl/curl.rb to install curl on my system.

  • Executed the following the command to set the curl on the PATH:

    export PATH="/opt/homebrew/opt/curl/bin:$PATH" >> ~/.zshrc
    source ~/.zshrc
    which curl
    
  • Then I have edited the host file via command sudo nano /etc/hosts (MacOS). In your case, you have to edit C:\Windows\System32\Drivers\etc\hosts for Windows to add the following ip and domain name.

    127.0.0.1       demo.local
    
  • Now, I have added the code base you have provided. Project Structure.

enter image description here

  • Running the code successfully. Screenshot:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.