位置头方案,得到http:/但想要https:/。

问题描述 投票:0回答:1

我有一个spring boot服务和一个运行在app engine上的angular应用。我正在使用一个 dispatch.yaml 该重定向 */api/* 到服务中。

服务在(http)响应中添加一个Location头,但这只是因为代码覆盖了方案。

    URI uri = ServletUriComponentsBuilder.fromCurrentRequestUri ()
        .scheme ("https")
        .replacePath ("/api/processor/{id}")
        .buildAndExpand(processingId)
        .encode ()
        .toUri ();

    return ResponseEntity
        .accepted ()
        .location (uri)
        .body (processingId);

调用 fromCurrentRequestUri() 有助于获得前端的主机名,而不是服务的主机名,但它确实使用了 http:// 而不是 https://. 该 scheme("https") 强制它使用https。

它得到http是有道理的,因为服务是在http "内部 "应用引擎运行的。从服务的角度来看,http位置是正确的,但从前端的角度来看是错误的。

有没有办法通过一些应用引擎的配置将Location头重写成https:/,这样对前端来说就是正确的?

spring-boot google-app-engine
1个回答
0
投票

有一种方法可以强制所有的HTTP请求重定向到HTTPS,这是用以下方法完成的 处理者 中的应用程序.yaml

在app.yaml中添加以下几行内容。

- url: /.*
  secure: always
  script: auto

© www.soinside.com 2019 - 2024. All rights reserved.