Check whether conditional requests are required.
@param required whether conditional requests are required
@param ifMatch the If-Match header
@param ifUnmodifiedSince the If-Unmodified-Since header
436411
public static void checkRequiredPreconditions(final boolean required, final String ifMatch,
            final String ifUnmodifiedSince) {
        if (required && ifMatch == null && ifUnmodifiedSince == null) {
            throw new ClientErrorException(status(PRECONDITION_REQUIRED).build());
        }
    }
468531
function(methodDef, callback, params, payload) {
        // check required params
        for (var index in methodDef.required_params) {
            var requiredParamName = methodDef.required_params[index];
            if (!params.hasOwnProperty(requiredParamName)) {
                callback(requiredParamName +' param is required');
                return false;
            }
        }
        // check unattended params
        if (methodDef.unattended_params === false) {
            for (var param in params) {
                if (methodDef.optional_params.indexOf(param) == -1
                    && methodDef.required_params.indexOf(param) == -1) {
                    callback('unattended param '+ param);
                    return false;
                }
            }
        }
        // TODO: optional_payload is also on spore specification
        if (!payload && methodDef.required_payload === true) {
            callback("payload is required");
            return false;
        }
        return true;
    }
82163
@InternalFunction(precedence=1,isAssign=true)
    public void require(RuleContext ruleContext,RuleProxyField ruleProxyField)
    {
        setRequired(ruleProxyField,ruleContext);
    }
1131763
public void checkAllRequirementsSatisfied(final String currentPath) {
        StringBuilder errors = new StringBuilder();

        for (Field field: this.dependantsInJson) {
            final Collection<String> requirements = this.dependantToRequirementsMap.get(field);
            if (!requirements.isEmpty()) {
                errors.append("\n");
                String type = field.getType().getName();
                if (field.getType().isArray()) {
                    type = field.getType().getComponentType().getName() + "[]";
                }
                errors.append("\t* ").append(type).append(' ').append(field.getName()).append(" depends on ")
                        .append(requirements);
            }
        }
        Assert.equals(0, errors.length(),
                      "\nErrors were detected when analysing the @Requires dependencies of '" +
                              currentPath + "': " + errors);
    }
568796
def required_header(header):
    
    if header in IGNORE_HEADERS:
        return False

    if header.startswith('HTTP_') or header == 'CONTENT_TYPE':
        return True

    return False
337678
private boolean checkZoneRequirement(HashMap<Integer, Integer> requiredRepFactor, int zoneId) {
        if(requiredRepFactor.containsKey(zoneId)) {
            if(requiredRepFactor.get(zoneId) == 0) {
                return false;
            } else {
                requiredRepFactor.put(zoneId, requiredRepFactor.get(zoneId) - 1);
                return true;
            }
        }
        return false;

    }
1287760
public boolean addDynamicRequire(String require) {
    if (!dynamicRequires.contains(require)) {
      dynamicRequires.add(require);
      return true;
    }
    return false;
  }
433041
public void checkContentType(final HttpServletRequest request) {
    String reqpar = request.getParameter(getContentTypeRequestName());

    if (reqpar != null) {
      if (reqpar.equals("!")) {
        // Go back to unsticky content type
        setContentTypeSticky(false);
      } else {
        setContentType(reqpar);
        setContentTypeSticky(false);
      }
    }

    reqpar = request.getParameter(getContentTypeStickyRequestName());
    if (reqpar != null) {
      if (reqpar.equals("!")) {
        // Go back to unsticky content type
        setContentTypeSticky(false);
      } else {
        setContentType(reqpar);
        setContentTypeSticky(true);
      }
    }
  }
717280
protected <T> boolean checkIfModified(CachedResource<T> cachedResource) {
        final Resource resource = cachedResource.getResource();

        // Check if the resource has been modified since it was last loaded.
        final long lastLoadTime = cachedResource.getLastLoadTime();
        final long mainLastModified = this.getLastModified(resource);
        boolean resourceModified = lastLoadTime < mainLastModified;
        if (resourceModified) {
            this.logger.trace(
                    "Resource {} was modified at {}, reloading",
                    new Object[] {resource, mainLastModified});
            return true;
        }

        // If the main resource hasn't changed check additional resources for modifications
        for (final Map.Entry<Resource, Long> additionalResourceEntry :
                cachedResource.getAdditionalResources().entrySet()) {
            final Resource additionalResource = additionalResourceEntry.getKey();
            final Long resourceLastLoadTime = additionalResourceEntry.getValue();

            final long lastModified = this.getLastModified(additionalResource);
            if (resourceLastLoadTime < lastModified) {
                this.logger.trace(
                        "Additional resource {} for {} was modified at {}, reloading",
                        new Object[] {additionalResource, resource, lastModified});
                return true;
            }
        }

        this.logger.trace(
                "{} has not been modified since last loaded {}, returning",
                cachedResource,
                lastLoadTime);
        return false;
    }
1296262
public static void writeIfModified(HttpAcceptSession httpSession, File requestFile) throws IOException {
        if (requestFile.isFile() && requestFile.exists()) {
            String etag = getETagHeaderValue(requestFile);
            String ifNoneMatch = httpSession.getReadHeader("If-None-Match");
            String ifModifiedSince = httpSession.getReadHeader("If-Modified-Since");
            if (!hasBeenModified(requestFile, etag, ifNoneMatch, ifModifiedSince)) {
                httpSession.setWriteHeader("ETag", etag);
                httpSession.setStatus(REDIRECT_NOT_MODIFIED);
            }
            else {
                FileInputStream in = new FileInputStream(requestFile);

                byte[] buf = new byte[8192];
                IoBufferAllocatorEx<?> allocator = httpSession.getBufferAllocator();
                IoBufferEx out = allocator.wrap(allocator.allocate(in.available())).setAutoExpander(allocator);
                int length;
                while ((length = in.read(buf)) > 0) {
                    out.put(buf, 0, length);
                }
                out.flip();
                in.close();
                httpSession.setWriteHeader("ETag", etag);
                httpSession.setWriteHeader("Last-Modified", RFC822_FORMAT_PATTERN.format(requestFile.lastModified()));
                httpSession.setWriteHeader("Expires", RFC822_FORMAT_PATTERN.format(System.currentTimeMillis()));
                httpSession.suspendWrite();
                httpSession.write(out);
                httpSession.shutdownWrite();
                httpSession.resumeWrite();

                // Note: callers are responsible for adding the Content-Type header,
                // per KG-866.  See HttpCrossSiteBridgeFilter for an example.
            }
        }
        else {
            httpSession.setStatus(CLIENT_NOT_FOUND);
        }
    }
843738
public void checkRequired(String key) throws InitializationFailedException {
    if (properties.get(key) == null && getConfigurationValue(key) == null) {
      throw new InitializationFailedException("Missing required property in config: " + key);
    }
  }
22767
final boolean isDeniedExplicitly(String subjectid, String resourcePath, String httpMethod) {
		if (StringUtils.isBlank(subjectid) || StringUtils.isBlank(resourcePath) ||
				StringUtils.isBlank(httpMethod) || getResourcePermissions().isEmpty()) {
			return false;
		}
		// urlDecode resource path
		resourcePath = Utils.urlDecode(resourcePath);
		if (getResourcePermissions().containsKey(subjectid)) {
			if (getResourcePermissions().get(subjectid).containsKey(resourcePath)) {
				return !isAllowed(subjectid, resourcePath, httpMethod);
			} else if (getResourcePermissions().get(subjectid).containsKey(ALLOW_ALL)) {
				return !isAllowed(subjectid, ALLOW_ALL, httpMethod);
			}
		}
		return false;
	}
1340177
private void validateIfdFP(IFD ifd, int p) {
    IfdTags metadata = ifd.getMetadata();

    checkRequiredTag(metadata, "ImageDescription", 1);
    checkRequiredTag(metadata, "StripOffsets", 1);
    if (p == 1 || p == 2) {
      checkRequiredTag(metadata, "StripOffsets", 1, new long[]{0});
    }
    checkRequiredTag(metadata, "NewSubfileType", 1);
    checkRequiredTag(metadata, "ImageLength", 1);
    checkRequiredTag(metadata, "ImageWidth", 1);
    checkRequiredTag(metadata, "StripOffsets", 1);
    if (p == 0) {
      checkRequiredTag(metadata, "Orientation", 1, new long[]{1,4,5,8});
    } else {
      checkRequiredTag(metadata, "Orientation", 1, new long[]{1});
    }
    checkRequiredTag(metadata, "StripBYTECount", 1);
    checkRequiredTag(metadata, "XResolution", 1);
    checkRequiredTag(metadata, "YResolution", 1);
    checkRequiredTag(metadata, "PlanarConfiguration", 1, new long[]{2});
    if (p == 1 || p == 2) {
      checkRequiredTag(metadata, "ResolutionUnit", 1, new long[]{2, 3});
      checkRequiredTag(metadata, "NumberOfInks", 1, new long[]{4});
    }
  }
92025
@Override
	public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) {
		if (!Constants.PARAM_HISTORY.equals(theRequest.getOperation())) {
			return false;
		}
		if (theRequest.getResourceName() == null) {
			return myResourceOperationType == RestOperationTypeEnum.HISTORY_SYSTEM;
		}
		if (!StringUtils.equals(theRequest.getResourceName(), myResourceName)) {
			return false;
		}

		boolean haveIdParam = theRequest.getId() != null && !theRequest.getId().isEmpty();
		boolean wantIdParam = myIdParamIndex != null;
		if (haveIdParam != wantIdParam) {
			return false;
		}

		if (theRequest.getId() == null) {
			return myResourceOperationType == RestOperationTypeEnum.HISTORY_TYPE;
		} else if (theRequest.getId().hasVersionIdPart()) {
			return false;
		}

		return true;
	}
763162
@Override
    protected void sideEffectRequestToCancel(final BinaryRequest request) {
        super.sideEffectRequestToCancel(request);

        if (request instanceof BinaryStoreRequest) {
            ((BinaryStoreRequest) request).content().release();
        } else if (request instanceof AppendRequest) {
            ((AppendRequest) request).content().release();
        } else if (request instanceof PrependRequest) {
            ((PrependRequest) request).content().release();
        }
    }
810642
public static void checkIfNoneMatch(final String method, final String ifNoneMatch, final EntityTag etag) {
        if (ifNoneMatch == null) {
            return;
        }

        final Set<String> items = stream(ifNoneMatch.split(",")).map(String::trim).collect(toSet());
        if (isGetOrHead(method)) {
            if ("*".equals(ifNoneMatch) || items.stream().map(EntityTag::valueOf)
                    .anyMatch(e -> e.equals(etag) || e.equals(new EntityTag(etag.getValue(), !etag.isWeak())))) {
                throw new RedirectionException(notModified().build());
            }
        } else {
            if ("*".equals(ifNoneMatch) || items.stream().map(EntityTag::valueOf).anyMatch(isEqual(etag))) {
                throw new ClientErrorException(status(PRECONDITION_FAILED).build());
            }
        }
     }
373315
@Override
	public void prepareConditionalGet(final HttpUriRequest newRequest) {
		transferFirstHeader("ETag", "If-None-Match", this.response, newRequest);
		transferFirstHeader("Last-Modified", "If-Modified-Since", this.response, newRequest);
	}