Skip to content

Commit

Permalink
Merge pull request #6081 from ant-media/release/2.8.2
Browse files Browse the repository at this point in the history
Release/2.8.2
  • Loading branch information
mekya authored Feb 2, 2024
2 parents 8cdc9bc + 60d7f33 commit 538589e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<groupId>io.antmedia</groupId>
<artifactId>parent</artifactId>
<version>2.8.0-SNAPSHOT</version>
<version>2.8.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ant-media-server</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/io/antmedia/filter/HttpForwardFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
27 changes: 25 additions & 2 deletions src/test/java/io/antmedia/test/filter/HttpForwardFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");

}


}
Expand Down

0 comments on commit 538589e

Please sign in to comment.