title: spring boot using HATEOAS generates links without host and port
body: <p>I am using spring boot version <code>2.0.6</code> which comes with HATEOAS version <code>0.25</code>. I am using a resource assembler that utlises <code>ControllerLinkBuilder</code> to generate resource links. However, the problem is it generates relative links, how to configure it to use a <code>host</code> and <code>port</code> scheme from either request headers (the app will run as a docker container in dev, qa and prod) or config properties when running it locally from IDE. </p>
  
  <p>I get link that respects <code>X-Forwarded-Host</code> header</p>
  
  <pre><code>"_links": {
          "self": {
              "href": "http://something.io/data/api/customers"
          }
      }
  </code></pre>
  
  <p>if I explicitly add header <code>X-Forwarded-Host</code> and generate the self link with this code</p>
  
  <pre><code>Link self = new Link(
                          ServletUriComponentsBuilder.fromRequestUri(request).buildAndExpand(pageable).toUri().toString(),
                          "self");
  </code></pre>
  
  <p>But when in resource assembler I rely on the usual <code>linkTo</code> calls from <code>ControllerLinkBuilder</code> the host and port are not rendered in the link.</p>
  
  <pre><code>"_links": {
          "self": {
              "href": "/customers/1"
          },
          "customers": {
              "href": "/customers"
          },
          "contact": {
              "href": "/customers/1/contact"
          }
      }
  </code></pre>
  
  <p>The controller definition </p>
  
  <pre><code>@Slf4j
  @RestController
  @RequestMapping("/customers")
  @ExposesResourceFor(Customer.class)
  public class CustomerController {
  }
  </code></pre>
  
  <p>and the get method </p>
  
  <pre><code>@GetMapping(produces = MediaTypes.HAL_JSON_VALUE)
      public DeferredResult&lt;ResponseEntity&lt;Resources&lt;Resource&lt;Customer&gt;&gt;&gt;&gt; getAllCustomers(
              @PageableDefault(page = 0, size = 20, sort = "name", direction = Direction.ASC) Pageable pageable,
              PagedResourcesAssembler&lt;Customer&gt; assembler, HttpServletRequest request) {
  }
  </code></pre>
  
  <p>I'm passing request object here because <code>linkTo</code> gives a url without host and port</p>
  
  <p>And I'm using a Customer Resource assembler <a href="https://github.com/spring-projects/spring-hateoas-examples/blob/master/commons/src/main/java/org/springframework/hateoas/SimpleIdentifiableResourceAssembler.java" rel="nofollow noreferrer">from the code here</a>, spring hateoas exmaples which is autowired to this controller </p>
  
  <pre><code>@Autowired
  private CustomerResourceAssember customerResourceAssembler;
  </code></pre>
  
  <p>and this is how I call paged resource assembler</p>
  
  <pre><code>assembler.toResource(result, customerResourceAssembler, self)
  </code></pre>