Return the submitted content type, either through a "format" parameter,
the HTTP content type header. If the content type is application/xml",
return "text/xml".

@param request
@return content type
770372
static String getConsumedContentType(HttpServletRequest request) {
        String mimeType = firstNotNull(request.getParameter("format"), request
                .getContentType());

        return ((mimeType != null) ? mimeType.replace("application/xml",
                BaseRestResource.XML) : null);
    }
1105515
public static Map<String, Object> convertRequestToMap(
            HttpServletRequest request) throws IOException, ServletException, JSONFormatException {

        Map<String, Object> inParams = new HashMap<String, Object>();

        //GET
        String q = request.getQueryString();
        if(!org.s1.objects.Objects.isNullOrEmpty(q)){
            String [] arr = q.split("&");
            for(String it:arr){
                String nv [] = it.split("=");
                String n = nv[0];
                String v = null;
                if(nv.length>1) {
                    v = nv[1];
                    try {
                        v = URLDecoder.decode(v, "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        throw S1SystemError.wrap(e);
                    }
                }
                if(PARAMS_PARAMETER.equals(n)){
                    inParams.putAll(Objects.fromWire(JSONFormat.evalJSON(v)));
                }else{
                    inParams.put(n,v);
                }
            }
        }
        if (request.getContentType()!=null && request.getContentType().contains("application/json")) {
            //JSON
            String s = IOUtils.toString(request.getInputStream(), "UTF-8");
            inParams = JSONFormat.evalJSON(s);
        } else if (request.getContentType()!=null
                && request.getContentType().contains("application/x-www-form-urlencoded")
                ) {
            //POST
            Iterator<Map.Entry<String, String[]>> it = request
                    .getParameterMap().entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String[]> e = it.next();
                String v = "" + e.getValue()[0];
                inParams.put(e.getKey(), v);
            }
        } else if (request.getContentType()!=null
                && request.getContentType().contains("multipart/form-data")
                ) {
            //parts
            for(Part p : request.getParts()){
                if(p.getContentType()!=null){
                    if(p.getSize()==0)
                        continue;
                    String name = p.getName();
                    //file
                    for (String content : p.getHeader("content-disposition").split(";")) {
                        if (content.trim().startsWith("filename")) {
                            name = content.substring(
                                    content.indexOf('=') + 1).trim().replace("\"", "");
                        }
                    }
                    String ext = "";
                    int ei = name.lastIndexOf(".");
                    if(ei!=-1 && ei<name.length()-1){
                        ext = name.substring(ei+1);
                        name = name.substring(0,ei);
                    }

                    inParams.put(p.getName(), new FileParameter(p.getInputStream(),name,ext,p.getContentType(),p.getSize()));
                }else{
                    //param
                    inParams.put(p.getName(), IOUtils.toString(p.getInputStream(),"UTF-8"));
                }
            }
        }
        inParams = Objects.fromWire(inParams);
        return inParams;
    }
309235
public static String getAppURL(HttpServletRequest request) {
		StringBuffer url = new StringBuffer();
		int port = request.getServerPort();
		if (port < 0) {
			port = 80; // Work around java.net.URL bug
		}
		String scheme = request.getScheme();
		url.append(scheme);
		url.append("://");
		url.append(request.getServerName());
		if ((scheme.equals("http") && (port != 80)) || (scheme.equals("https") && (port != 443))) {
			url.append(':');
			url.append(port);
		}
		return url.toString();
	}
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);
      }
    }
  }
466195
function(request) {
        var doc = request.responseXML;
        if (!doc || !doc.documentElement) {
            doc = request.responseText;
        }
        if (!doc || doc.length <= 0) {
            return null;
        }
        return this.format.read(doc);
    }
1310762
private function determineContentType(ServerRequestInterface $request)
    {
        $acceptHeader = $request->getHeaderLine('Accept');
        $selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
        if (count($selectedContentTypes)) {
            return reset($selectedContentTypes);
        }

        return 'text/html';
    }
464631
def content_type(self):
        
        type_formencoded = "application/x-www-form-urlencoded"

        ctype = self.request.META.get('CONTENT_TYPE', type_formencoded)

        if type_formencoded in ctype:
            return None

        return ctype
1217012
@Override
    public String getContentType() {
        String type = this.response.getHeader("Content-Type");
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getContentType: " + type);
        }
        return type;
    }
700522
public static Map<String, String> getRequestHeaders(final HttpServletRequest request) {
        val headers = new LinkedHashMap<String, Object>();
        val headerNames = request.getHeaderNames();
        if (headerNames != null) {
            while (headerNames.hasMoreElements()) {
                val headerName = headerNames.nextElement();
                val headerValue = StringUtils.stripToEmpty(request.getHeader(headerName));
                headers.put(headerName, headerValue);
            }
        }
        return (Map) headers;
    }
715898
private ContentType getAcceptType() {
        // If the format header is present, it overrides the ACCEPT header.
        String format = m_variableMap.get("format");
        if (format != null) {
            return new ContentType(format);
        }
        String acceptParts = m_request.getHeader(HttpDefs.ACCEPT);
        if (!Utils.isEmpty(acceptParts)) {
	        for (String acceptPart : acceptParts.split(",")) {
	            ContentType acceptType = new ContentType(acceptPart);
	            if (acceptType.isJSON() || acceptType.isXML() || acceptType.isPlainText()) {
	                return acceptType;
	            }
	        }
        }
        return getContentType();
    }
733721
protected long getContentLength(HttpServletRequest request) {
		if (useServlet31) {
			return request.getContentLengthLong();
		}
		String contentLengthHeader = request.getHeader(HttpHeaders.CONTENT_LENGTH);
		if (contentLengthHeader != null) {
			try {
				return Long.parseLong(contentLengthHeader);
			}
			catch (NumberFormatException e) {
			}
		}
		return request.getContentLength();
	}
661714
public KieServerHttpRequest contentType(final String contentType, final String charset ) {
        if( charset != null && charset.length() > 0 ) {
            final String separator = "; " + PARAM_CHARSET + '=';
            return header(CONTENT_TYPE, contentType + separator + charset);
        } else
            return header(CONTENT_TYPE, contentType);
    }
363035
private static String getContentPath(HttpServletRequest request) {

    String contentPath = (String)request.getAttribute(Value.CONTENTPATH_ATTRIBUTE);
    if (contentPath == null) {
      // fallback to suffix if CONTENTPATH_ATTRIBUTE is not set
      // (e.g. in inside a /libs/granite/ui/components/foundation/form/multifield component)
      contentPath = ((SlingHttpServletRequest)request).getRequestPathInfo().getSuffix();
    }

    return contentPath;
  }
680629
protected function getContentTypeHeader(Request $request): ContentType
	{
		$headerName = 'Content-Type';
		if (!$request->hasHeader($headerName))
		{
			throw new Exception\BadRequest('Content-Type header should be declared');
		}
		if (count($request->getHeader($headerName)) > 1)
		{
			throw new Exception\BadRequest('Multiple Content-Type headers are not allowed');
		}
		try
		{
			return ContentType::fromString($headerName . ': ' . $request->getHeaderLine($headerName));
		}
		catch (\Exception $e)
		{
			throw new Exception\BadRequest('Invalid Content-Type header', $e);
		}
	}
112751
@SuppressWarnings("Duplicates")
    public static Optional<Charset> resolveCharset(HttpMessage<?> request) {
        try {
            Optional<Charset> contentTypeCharset = request
                .getContentType()
                .flatMap(contentType ->
                    contentType.getParameters()
                        .get(MediaType.CHARSET_PARAMETER)
                        .map(Charset::forName)
                );

            if (contentTypeCharset.isPresent()) {
                return contentTypeCharset;
            } else {
                return request
                    .getHeaders()
                    .findFirst(HttpHeaders.ACCEPT_CHARSET)
                    .map(text -> {
                        int len = text.length();
                        if (len == 0 || (len == 1 && text.charAt(0) == '*')) {
                            return StandardCharsets.UTF_8;
                        }
                        if (text.indexOf(';') > -1) {
                            text = text.split(";")[0];
                        }
                        if (text.indexOf(',') > -1) {
                            text = text.split(",")[0];
                        }
                        try {
                            return Charset.forName(text);
                        } catch (Exception e) {
                            // unsupported charset, default to UTF-8
                            return StandardCharsets.UTF_8;
                        }
                    });
            }
        } catch (UnsupportedCharsetException e) {
            return Optional.empty();
        }
    }
755972
def content_type(self, request=None, response=None):
        """"""
        if callable(self.outputs.content_type):
            return self.outputs.content_type(request=request, response=response)
        else:
            return self.outputs.content_type
713696
public static RequestContent getRequestContent(HttpServletRequest request,
                                            HttpHeaders headers)
    throws Exception {
        RequestContent rContent = null;

        // See if the request is a multi-part file upload request
        if(ServletFileUpload.isMultipartContent(request)) {

        	logger.debug("processing multipart content...");
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload();

            // Parse the request, use the first available File item
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                if (!item.isFormField()) {
                    rContent = new RequestContent();
                    rContent.contentStream = item.openStream();
                    rContent.mimeType = item.getContentType();

                    FileItemHeaders itemHeaders = item.getHeaders();
                    if(itemHeaders != null) {
                        String contentLength = itemHeaders.getHeader("Content-Length");
                        if(contentLength != null) {
                            rContent.size = Long.parseLong(contentLength);
                        }
                    }

                    break;
                } else {
                	logger.trace("ignoring form field \"{}\" \"{}\"", item.getFieldName(), item.getName());
                }
            }
        } else {
            // If the content stream was not been found as a multipart,
            // try to use the stream from the request directly
            if(rContent == null) {
                String contentLength = request.getHeader("Content-Length");
                long size = 0;
                if(contentLength != null) {
                    size = Long.parseLong(contentLength);
                } else size = request.getContentLength();
                if (size > 0) {
                  rContent = new RequestContent();
                  rContent.contentStream = request.getInputStream();
                  rContent.size = size;
                } else {
                    String transferEncoding =
                            request.getHeader("Transfer-Encoding");
                    if (transferEncoding != null && transferEncoding.contains("chunked")) {
                        BufferedInputStream bis =
                            new BufferedInputStream(request.getInputStream());
                        bis.mark(2);
                        if (bis.read() > 0) {
                            bis.reset();
                            rContent = new RequestContent();
                            rContent.contentStream = bis;
                        }
                    } else {
                    	logger.warn(
                    			"Expected chunked data not found- " +
                    	        "Transfer-Encoding : {}, Content-Length: {}",
                    	        transferEncoding, size);
                    }
                }
            }
        }

        // Attempt to set the mime type and size if not already set
        if(rContent != null) {
            if(rContent.mimeType == null) {
                MediaType mediaType = headers.getMediaType();
                if(mediaType != null) {
                    rContent.mimeType = mediaType.toString();
                }
            }

            if(rContent.size == 0) {
                List<String> lengthHeaders =
                    headers.getRequestHeader("Content-Length");
                if(lengthHeaders != null && lengthHeaders.size() > 0) {
                    rContent.size = Long.parseLong(lengthHeaders.get(0));
                }
            }
        }

        return rContent;
    }