Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Use ServletRequest.getLocalPort() to get real port, not host header p…
Browse files Browse the repository at this point in the history
…ort.
  • Loading branch information
chriseldredge committed Jul 28, 2015
1 parent c319c02 commit f473208
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
<version>2.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PoweredByResponseHeaderFilter implements Filter

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.addHeader(headerName, host + ":" + request.getServerPort());
httpResponse.addHeader(headerName, host + ":" + request.getLocalPort());

filterChain.doFilter(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected void setUp() throws Exception {

public void testSetsHeader() throws Exception {
Mockito.when(request.getServerName()).thenReturn("snorkle01.example.com");
Mockito.when(request.getServerPort()).thenReturn(8087);
Mockito.when(request.getServerPort()).thenReturn(80);
Mockito.when(request.getLocalPort()).thenReturn(8087);

filter.doFilter(request, response, chain);

Expand Down

0 comments on commit f473208

Please sign in to comment.