public void setCachingHeaders(HttpServletResponse resp, int ttl, boolean noProxy) { if (ttl < 0) { HttpUtil.setCachingHeaders(resp, noProxy); } else if (ttl == 0) { HttpUtil.setNoCache(resp); } else { HttpUtil.setCachingHeaders(resp, ttl, noProxy); } } }
public static List<Pair<String, String>> getCachingHeadersToSet(int ttl, boolean noProxy) { return getCachingHeadersToSet(ttl, null, null, noProxy); }
protected long getDefaultExpiration() { return timeSource.currentTimeMillis() + (HttpUtil.getDefaultTtl() * 1000); }
@Test public void testSetCachingHeadersAllowProxy() { HttpUtil.setCachingHeaders(recorder, false); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpUtil.setNoCache(response); String path = request.getPathInfo(); if (path.endsWith(AUTHORIZE)) { sendOAuth2Response(response, authorizationHandler.handle(request, response)); } else if (path.endsWith(TOKEN)) { //token endpoint must use POST method response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The client MUST use the HTTP \"POST\" method " + "when making access token requests."); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown URL"); } }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param ttl The time to cache for, in seconds. If 0, then insure that * this object is not cached. */ public static void setCachingHeaders(HttpServletResponse response, int ttl) { setCachingHeaders(response, ttl, false); }
/** * Actual dispatch handling for servlet requests */ void executeRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException { if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Handling restful request for " + servletRequest.getPathInfo()); } setCharacterEncodings(servletRequest, servletResponse); SecurityToken token = getSecurityToken(servletRequest); if (token == null) { sendSecurityError(servletResponse); return; } HttpUtil.setCORSheader(servletResponse, containerConfig.<String>getList(token.getContainer(), "gadgets.parentOrigins")); handleSingleRequest(servletRequest, servletResponse, token); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String reqValue; String callbackValue; try { HttpUtil.isJSONP(request); reqValue = validateParameterValue(request, GET_REQUEST_REQ_PARAM); callbackValue = validateParameterValue(request, GET_REQUEST_CALLBACK_PARAM); } catch (IllegalArgumentException e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); LOG.log(Level.INFO, e.getMessage(), e); return; } Result result = process(request, response, reqValue); response.getWriter().write(result.isSuccess() ? callbackValue + '(' + result.getOutput() + ')' : result.getOutput()); }
HttpUtil.setCORSheader(servletResponse, containerConfig.<String>getList(token.getContainer(), "gadgets.parentOrigins")); } else if (HttpUtil.isJSONP(servletRequest)) { content = servletRequest.getParameter("request"); callback = servletRequest.getParameter("callback");
public static void setTimeSource(TimeSource timeSource) { HttpUtil.setTimeSource(timeSource); }
public static TimeSource getTimeSource() { return HttpUtil.getTimeSource(); }
@Test public void testSetCachingHeaders() { HttpUtil.setCachingHeaders(recorder); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpUtil.setNoCache(response); String path = request.getPathInfo(); if (path.endsWith(AUTHORIZE)) { sendOAuth2Response(response, authorizationHandler.handle(request, response)); } else if (path.endsWith(TOKEN)) { //token endpoint must use POST method response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The client MUST use the HTTP \"POST\" method " + "when making access token requests."); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown URL"); } }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param noProxy True if you don't want the response to be cacheable by proxies. */ public static void setCachingHeaders(HttpServletResponse response, boolean noProxy) { setCachingHeaders(response, defaultTtl, noProxy); }
@Test @Ignore("HttpServletResponseRecorder doesn't support multiple headers") public void testCORSmultiple() { HttpUtil.setCORSheader(recorder, Arrays.asList("http://foo.example.com", "http://bar.example.com")); // TODO fix HttpServletResponseRecorder and add multi-header test here }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String reqValue; String callbackValue; try { HttpUtil.isJSONP(request); reqValue = validateParameterValue(request, GET_REQUEST_REQ_PARAM); callbackValue = validateParameterValue(request, GET_REQUEST_CALLBACK_PARAM); } catch (IllegalArgumentException e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); LOG.log(Level.INFO, e.getMessage(), e); return; } Result result = process(request, response, reqValue); response.getWriter().write(result.isSuccess() ? callbackValue + '(' + result.getOutput() + ')' : result.getOutput()); }
HttpUtil.setCORSheader(servletResponse, containerConfig.<String>getList(token.getContainer(), "gadgets.parentOrigins")); } else if (HttpUtil.isJSONP(servletRequest)) { content = servletRequest.getParameter("request"); callback = servletRequest.getParameter("callback");
public static void setTimeSource(TimeSource timeSource) { HttpUtil.setTimeSource(timeSource); }
public static TimeSource getTimeSource() { return HttpUtil.getTimeSource(); }
@Test public void testSetCachingHeadersAllowProxy() { HttpUtil.setCachingHeaders(recorder, false); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }