diff --git a/pom.xml b/pom.xml index df5061f15..6cdf03349 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ io.antmedia parent - 2.8.0-SNAPSHOT + 2.8.3-SNAPSHOT 4.0.0 ant-media-server diff --git a/src/main/java/io/antmedia/filter/HttpForwardFilter.java b/src/main/java/io/antmedia/filter/HttpForwardFilter.java index 7052a4fc5..f56aee298 100644 --- a/src/main/java/io/antmedia/filter/HttpForwardFilter.java +++ b/src/main/java/io/antmedia/filter/HttpForwardFilter.java @@ -45,7 +45,15 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha { if (requestURI.endsWith(extension[i])) { - String redirectUri = httpForwardingBaseURL + requestURI.substring(requestURI.indexOf(SLASH, 1)); + String subURI = requestURI.substring(requestURI.indexOf(SLASH, 1)); + + //two back to back slashes cause problems + String normalizedBaseURL = httpForwardingBaseURL.endsWith(SLASH) ? httpForwardingBaseURL : httpForwardingBaseURL + SLASH; + + String normalizedSubURI = subURI.startsWith(SLASH) ? subURI.substring(1) : subURI; + + String redirectUri = normalizedBaseURL + normalizedSubURI; + HttpServletResponse httpResponse = (HttpServletResponse) response; if (redirectUri.contains(DOUBLE_DOT)) { throw new IOException("URI is not well formatted"); diff --git a/src/test/java/io/antmedia/test/filter/HttpForwardFilterTest.java b/src/test/java/io/antmedia/test/filter/HttpForwardFilterTest.java index 5f26f4e39..dea11cdc7 100644 --- a/src/test/java/io/antmedia/test/filter/HttpForwardFilterTest.java +++ b/src/test/java/io/antmedia/test/filter/HttpForwardFilterTest.java @@ -62,8 +62,8 @@ public void testDoFilterPass() throws IOException, ServletException httpForwardFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); //chain filter should not be called because base url is et Mockito.verify(filterChain, Mockito.times(5)).doFilter(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendRedirect("http://url//streams/test.m3u8"); - + Mockito.verify(httpServletResponse).sendRedirect("http://url/streams/test.m3u8"); + httpServletRequest.setRequestURI(null); httpForwardFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); @@ -119,6 +119,29 @@ public void testDoFilterPass() throws IOException, ServletException httpForwardFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); //it should not increase because it's ok to forward Mockito.verify(filterChain, Mockito.times(9)).doFilter(httpServletRequest, httpServletResponse); + + { + appSettings.setHttpForwardingExtension("m3u8"); + appSettings.setHttpForwardingBaseURL("http://url"); + httpServletRequest.setRequestURI("/LiveApp/streams/test.m3u8"); + + httpForwardFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); + //chain filter should not be called because base url is et + // Mockito.verify(filterChain, Mockito.times(5)).doFilter(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse, Mockito.times(2)).sendRedirect("http://url/streams/test.m3u8"); + } + + { + appSettings.setHttpForwardingExtension("m3u8"); + appSettings.setHttpForwardingBaseURL("http://url"); + httpServletRequest.setRequestURI("LiveApp/streams/test.m3u8"); + + httpForwardFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); + //chain filter should not be called because base url is et + // Mockito.verify(filterChain, Mockito.times(5)).doFilter(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse, Mockito.times(3)).sendRedirect("http://url/streams/test.m3u8"); + + } }