-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HH-88962 Parse source and load testing headers
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
nab-starter/src/main/java/ru/hh/nab/starter/filters/CommonHeadersFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ru.hh.nab.starter.filters; | ||
|
||
import org.springframework.web.filter.OncePerRequestFilter; | ||
import ru.hh.nab.starter.http.RequestContext; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public final class CommonHeadersFilter extends OncePerRequestFilter { | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, | ||
HttpServletResponse response, | ||
FilterChain filterChain) throws ServletException, IOException { | ||
|
||
String source = request.getHeader(RequestHeaders.REQUEST_SOURCE); | ||
boolean isLoadTesting = request.getHeader(RequestHeaders.LOAD_TESTING) != null; | ||
|
||
try { | ||
RequestContext.setRequestSource(source); | ||
RequestContext.setLoadTesting(isLoadTesting); | ||
|
||
filterChain.doFilter(request, response); | ||
|
||
} finally { | ||
RequestContext.clearRequestSource(); | ||
RequestContext.clearLoadTesting(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
nab-starter/src/main/java/ru/hh/nab/starter/http/RequestContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.hh.nab.starter.http; | ||
|
||
public class RequestContext { | ||
private static final ThreadLocal<String> REQUEST_SOURCE = new ThreadLocal<>(); | ||
private static final ThreadLocal<Boolean> LOAD_TESTING = new ThreadLocal<>(); | ||
|
||
public static String getRequestSource() { | ||
return REQUEST_SOURCE.get(); | ||
} | ||
|
||
public static void setRequestSource(String source) { | ||
REQUEST_SOURCE.set(source); | ||
} | ||
|
||
public static void clearRequestSource() { | ||
REQUEST_SOURCE.remove(); | ||
} | ||
|
||
public static boolean isLoadTesting() { | ||
return Boolean.TRUE.equals(LOAD_TESTING.get()); | ||
} | ||
|
||
public static void setLoadTesting(boolean isLoadTesting) { | ||
LOAD_TESTING.set(isLoadTesting); | ||
} | ||
|
||
public static void clearLoadTesting() { | ||
LOAD_TESTING.remove(); | ||
} | ||
} |