亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SpringBoot 可能存在重定向過濾問題

SpringBoot 可能存在重定向過濾問題

守候你守候我 2021-09-15 17:06:09
在此處的其他問題之一中,我讀到這是某物在其他地方損壞的癥狀。問題是,我的整個 SpringBoot 應用程序只為一些HTML帶有翻譯的頁面提供服務。沒有什么花哨。然后,我挖掘更多的轉化項目,我發現某種以便從用戶重定向實現濾波器HTTP來HTTPS。我想這是問題的根本原因,但我很難理解為什么。@Componentpublic class HttpsRedirectionFilter extends GenericFilterBean {    @Override    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {        HttpServletRequest httpRequest = (HttpServletRequest) request;        HttpServletResponse httpResponse = (HttpServletResponse) response;        String protocol = httpRequest.getHeader("x-forwarded-proto");        if ("http".equalsIgnoreCase(protocol)) {            String redirectURL = "https://" + httpRequest.getServerName() + httpRequest.getRequestURI();            httpResponse.sendRedirect(redirectURL);        }        filterChain.doFilter(request, response);    }}嘗試調試它(這不是超級容易,因為我沒有在本地安裝任何證書),我看到每次訪問都多次調用此方法(4-5)。任何人都可以請指出我的錯誤并向我解釋為什么它會產生如此多的異常?
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

嘗試這個,


if ("http".equalsIgnoreCase(protocol)) {

    String redirectURL = "https://" + httpRequest.getServerName() + httpRequest.getRequestURI();

    httpResponse.sendRedirect(redirectURL);

} else {

    filterChain.doFilter(request, response);

}


查看完整回答
反對 回復 2021-09-15
  • 1 回答
  • 0 關注
  • 341 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號