List of usage examples for com.google.common.net HttpHeaders CACHE_CONTROL
String CACHE_CONTROL
To view the source code for com.google.common.net HttpHeaders CACHE_CONTROL.
Click Source Link
From source file:org.haiku.haikudepotserver.pkg.controller.PkgIconController.java
/** * @param isAsFallback is true if the request was originally for a package, but fell back to this generic. *//* w w w . j a v a2 s .com*/ private void handleGenericHeadOrGet(RequestMethod requestMethod, HttpServletResponse response, Integer size, boolean isAsFallback) throws IOException { if (null == size) { size = 64; // largest natural size } size = normalizeSize(size); byte[] data = renderedPkgIconRepository.renderGeneric(size); response.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(data.length)); response.setContentType(MediaType.PNG.toString()); if (isAsFallback) { response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate"); response.setHeader(HttpHeaders.PRAGMA, "no-cache"); response.setHeader(HttpHeaders.EXPIRES, "0"); } else { response.setDateHeader(HttpHeaders.LAST_MODIFIED, startupMillis); } if (requestMethod == RequestMethod.GET) { response.getOutputStream().write(data); } }
From source file:org.haiku.haikudepotserver.job.controller.JobController.java
/** * <p>This URL can be used to download job data that has resulted from a job being run.</p> *///from w w w . j a v a2 s.c o m @RequestMapping(value = "/" + SEGMENT_JOBDATA + "/{" + KEY_GUID + "}/" + SEGMENT_DOWNLOAD, method = RequestMethod.GET) public void downloadGeneratedData(HttpServletRequest request, HttpServletResponse response, @PathVariable(value = KEY_GUID) String guid) throws IOException { Preconditions.checkArgument(PATTERN_GUID.matcher(guid).matches(), "the supplied guid does not match the required pattern"); ObjectContext context = serverRuntime.newContext(); JobSnapshot job = jobService.tryGetJobForData(guid).orElseThrow(() -> { LOGGER.warn("attempt to access job data {} for which no job exists", guid); return new JobDataAuthorizationFailure(); }); // If there is no user who is assigned to the job then the job is for nobody in particular and is thereby // secured by the GUID of the job's data; if you know the GUID then you can have the data. if (!Strings.isNullOrEmpty(job.getOwnerUserNickname())) { User user = tryObtainAuthenticatedUser(context).orElseThrow(() -> { LOGGER.warn("attempt to obtain job data {} with no authenticated user", guid); return new JobDataAuthorizationFailure(); }); User ownerUser = User.tryGetByNickname(context, job.getOwnerUserNickname()).orElseThrow(() -> { LOGGER.warn("owner of job does not seem to exist; {}", job.getOwnerUserNickname()); return new JobDataAuthorizationFailure(); }); if (!authorizationService.check(context, user, ownerUser, Permission.USER_VIEWJOBS)) { LOGGER.warn("attempt to access jobs view for; {}", job.toString()); throw new JobDataAuthorizationFailure(); } } else { LOGGER.debug("access to job [{}] allowed for unauthenticated access", job.toString()); } JobDataWithByteSource jobDataWithByteSink = jobService.tryObtainData(guid).orElseThrow(() -> { LOGGER.warn("requested job data {} not found", guid); return new JobDataAuthorizationFailure(); }); // finally access has been checked and the logic can move onto actual // delivery of the material. JobData jobData = jobDataWithByteSink.getJobData(); if (!Strings.isNullOrEmpty(jobData.getMediaTypeCode())) { response.setContentType(jobData.getMediaTypeCode()); } else { response.setContentType(MediaType.OCTET_STREAM.toString()); } response.setContentType(MediaType.CSV_UTF_8.toString()); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + jobService.deriveDataFilename(guid)); response.setDateHeader(HttpHeaders.EXPIRES, 0); response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache"); // now switch to async for the delivery of the data. AsyncContext async = request.startAsync(); async.setTimeout(TIMEOUT_DOWNLOAD_MILLIS); ServletOutputStream outputStream = response.getOutputStream(); outputStream.setWriteListener(new JobDataWriteListener(guid, jobService, async, outputStream)); LOGGER.info("did start async stream job data; {}", guid); }