title: How to get absolute webserver path in a Spring @RestController?
body: <p>I want my <code>@RestController</code> to return an absolute url path to my webserver. But the path should not be hardcoded, instead derived from the application server where the spring application runs in.</p>
  
  <pre><code>@RestController
  public class FileService {
       @GetMapping("/list")
       public String getFiles(String key) {
              String filepath = manager.getFile(key);
              //TODO how to return the file with absolute path to webserver?
       }
  }
  </code></pre>
  
  <p>Also, if the user requests the file via http, the server should respond with http. Likewise, if https is requested, https should be prefixed before the absolute url.</p>
  
  <p>Question: how can I get the absolute path inside the controller dynamically?</p>