MCPcopy Index your code
hub / github.com/apache/tomcat / parseParts

Method parseParts

java/org/apache/catalina/connector/Request.java:2545–2727  ·  view source on GitHub ↗
(boolean explicit)

Source from the content-addressed store, hash-verified

2543
2544
2545 private void parseParts(boolean explicit) {
2546
2547 // Return immediately if the parts have already been parsed
2548 if (parts != null || partsParseException != null) {
2549 return;
2550 }
2551
2552 Context context = getContext();
2553 MultipartConfigElement mce = getWrapper().getMultipartConfigElement();
2554
2555 if (mce == null) {
2556 if (context.getAllowCasualMultipartParsing()) {
2557 mce = new MultipartConfigElement(null, connector.getMaxPostSize(), connector.getMaxPostSize(),
2558 connector.getMaxPostSize());
2559 } else {
2560 if (explicit) {
2561 partsParseException = new IllegalStateException(sm.getString("coyoteRequest.noMultipartConfig"));
2562 } else {
2563 parts = Collections.emptyList();
2564 }
2565 return;
2566 }
2567 }
2568
2569 /*
2570 * When the request body is multipart/form-data, both the parts and the query string count towards
2571 * maxParameterCount. If parseParts() is called before getParameterXXX() then the parts will be parsed before
2572 * the query string. Otherwise, the query string will be parsed first.
2573 *
2574 * maxParameterCount must be respected regardless of which is parsed first.
2575 *
2576 * maxParameterCount is reset from the Connector at the start of every request.
2577 *
2578 * If parts are parsed first, non-file parts will be added to the parameter map and any files will reduce
2579 * maxParameterCount by 1 so that when the query string is parsed the difference between the size of the
2580 * parameter map and maxParameterCount will be the original maxParameterCount less the number of parts. i.e. the
2581 * maxParameterCount applied to the query string will be the original maxParameterCount less the number of
2582 * parts.
2583 *
2584 * If the query string is parsed first, all parameters will be added to the parameter map and, ignoring
2585 * maxPartCount, the part limit will be set to the original maxParameterCount less the size of the parameter
2586 * map. i.e. the maxParameterCount applied to the parts will be the original maxParameterCount less the number
2587 * of query parameters.
2588 */
2589 Parameters parameters = coyoteRequest.getParameters();
2590 parameters.setLimit(maxParameterCount);
2591
2592 File location;
2593 String locationStr = mce.getLocation();
2594 if (locationStr == null || locationStr.isEmpty()) {
2595 location = ((File) context.getServletContext().getAttribute(ServletContext.TEMPDIR));
2596 } else {
2597 // If relative, it is relative to TEMPDIR
2598 location = new File(locationStr);
2599 if (!location.isAbsolute()) {
2600 location =
2601 new File((File) context.getServletContext().getAttribute(ServletContext.TEMPDIR), locationStr)
2602 .getAbsoluteFile();

Callers 2

getPartsMethod · 0.95
doParseParametersMethod · 0.95

Calls 15

getContextMethod · 0.95
getWrapperMethod · 0.95
setLimitMethod · 0.95
getLocationMethod · 0.95
getServletContextMethod · 0.95
getMappingDataMethod · 0.95
setRepositoryMethod · 0.95
setSizeThresholdMethod · 0.95
getFileSizeThresholdMethod · 0.95
setFileItemFactoryMethod · 0.95

Tested by

no test coverage detected