Package org.languagetool.server
Class LanguageToolHttpHandler
java.lang.Object
org.languagetool.server.LanguageToolHttpHandler
- All Implemented Interfaces:
HttpHandler
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final Stringprivate final HTTPServerConfigprivate static final Stringprivate final ErrorRequestLimiterprivate final Serverprivate static final org.slf4j.Loggerprivate final RequestCounter(package private) static final Stringprivate final RequestLimiterprivate final TextCheckerprivate final BlockingQueue<Runnable> -
Constructor Summary
ConstructorsConstructorDescriptionLanguageToolHttpHandler(HTTPServerConfig config, Set<String> allowedIps, boolean internal, RequestLimiter requestLimiter, ErrorRequestLimiter errorLimiter, BlockingQueue<Runnable> workQueue, Server httpServer) -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanallowSkipRequestLimit(Headers requestHeaders) getParameterMap(String query, HttpExchange httpExchange) (package private) static StringgetRealRemoteAddressOrNull(HttpExchange httpExchange, HTTPServerConfig config) A (reverse) proxy can set the 'X-forwarded-for' header so we can see a user's original IP.(package private) static StringgetRequestId(HttpExchange httpExchange) getRequestQuery(HttpExchange httpExchange, URI requestedUri) private StringgetTextOrDataSizeMessage(Map<String, String> parameters) voidhandle(HttpExchange httpExchange) private booleanhasCause(Exception e, Class<AuthException> clazz) private booleanwhitelist paths from request limitingprivate voidprivate voidlogError(String errorMessage, int code, Map<String, String> params, HttpExchange httpExchange, boolean logToDb) private voidlogError(String remoteAddress, Exception e, int errorCode, HttpExchange httpExchange, Map<String, String> params, boolean textLoggingAllowed, boolean logStacktrace, long runtimeMillis) parseQuery(String query, HttpExchange httpExchange) private StringreaderToString(Reader reader, int maxTextLength) private voidsendError(HttpExchange httpExchange, int httpReturnCode, String response) (package private) voidshutdown()private booleantextCheckerQueueFull(HttpExchange httpExchange, String response) private booleanworkQueueFull(HttpExchange httpExchange, Map<String, String> parameters, String response)
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
API_DOC_URL
- See Also:
-
REQUEST_LIMIT_ACCESS_TOKEN_HEADER
- See Also:
-
ENCODING
- See Also:
-
allowedIps
-
requestLimiter
-
errorRequestLimiter
-
workQueue
-
httpServer
-
textCheckerV2
-
config
-
reqCounter
-
-
Constructor Details
-
LanguageToolHttpHandler
LanguageToolHttpHandler(HTTPServerConfig config, Set<String> allowedIps, boolean internal, RequestLimiter requestLimiter, ErrorRequestLimiter errorLimiter, BlockingQueue<Runnable> workQueue, Server httpServer)
-
-
Method Details
-
shutdown
void shutdown()- Since:
- 2.6
-
handle
- Specified by:
handlein interfaceHttpHandler- Throws:
IOException
-
allowSkipRequestLimit
-
limitPath
whitelist paths from request limiting -
getRequestId
-
hasCause
-
workQueueFull
private boolean workQueueFull(HttpExchange httpExchange, Map<String, String> parameters, String response) throws IOException- Throws:
IOException
-
textCheckerQueueFull
- Throws:
IOException
-
getTextOrDataSizeMessage
-
logError
private void logError(String errorMessage, int code, Map<String, String> params, HttpExchange httpExchange) -
logError
private void logError(String errorMessage, int code, Map<String, String> params, HttpExchange httpExchange, boolean logToDb) -
logError
-
getRealRemoteAddressOrNull
@Nullable static String getRealRemoteAddressOrNull(HttpExchange httpExchange, HTTPServerConfig config) A (reverse) proxy can set the 'X-forwarded-for' header so we can see a user's original IP. But that's just a common header than can also be set by the client. So we restrict access to this server to the load balancer, which should add the header originally with the user's own IP. -
sendError
private void sendError(HttpExchange httpExchange, int httpReturnCode, String response) throws IOException - Throws:
IOException
-
getRequestQuery
private Map<String,String> getRequestQuery(HttpExchange httpExchange, URI requestedUri) throws IOException - Throws:
IOException
-
readerToString
- Throws:
IOException
-
parseQuery
private Map<String,String> parseQuery(String query, HttpExchange httpExchange) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-
getParameterMap
private Map<String,String> getParameterMap(String query, HttpExchange httpExchange) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-