Get the HTML MIME type to use

@param aRequestScope
The request scope. May be <code>null</code>-
@return Never <code>null</code>.
339453
@Nonnull
  public static IMimeType getMimeType (@Nullable final IRequestWebScopeWithoutResponse aRequestScope)
  {
    // Add the charset to the MIME type
    return new MimeType (CMimeType.TEXT_HTML).addParameter (CMimeType.PARAMETER_NAME_CHARSET,
                                                            HCSettings.getHTMLCharset ().name ());
  }
151631
public static HttpServletRequest getOuterRequest( HttpServletRequest request )
    {
        ScopedRequest scopedRequest = unwrapRequest( request );
        return scopedRequest != null ? scopedRequest.getOuterRequest() : request;
    }
1346411
protected IScriptReporter getHtmlTag(ServletRequest req)
    {
        Html html = (Html) req.getAttribute(Html.HTML_TAG_ID);
        if (html != null && html instanceof IScriptReporter)
            return (IScriptReporter) html;
        return null;
    }
34761
private static AbstractWebApplicationService determineWebApplicationFormat(final HttpServletRequest request,
                                                                               final AbstractWebApplicationService webApplicationService) {
        val format = request != null ? request.getParameter(CasProtocolConstants.PARAMETER_FORMAT) : null;
        try {
            if (StringUtils.isNotBlank(format)) {
                val formatType = ValidationResponseType.valueOf(format.toUpperCase());
                webApplicationService.setFormat(formatType);
            }
        } catch (final Exception e) {
            LOGGER.error("Format specified in the request [{}] is not recognized", format);
        }
        return webApplicationService;
    }
351817
protected CORSRequestType checkRequestType(final HttpServletRequest request) {
        CORSRequestType requestType = CORSRequestType.INVALID_CORS;
        if (request == null) {
            throw new IllegalArgumentException("Request is null");
        }
        String originHeader = request.getHeader(REQUEST_HEADER_ORIGIN);
        // Section 6.1.1 and Section 6.2.1
        if (originHeader != null) {
            if (originHeader.isEmpty()) {
                requestType = CORSRequestType.INVALID_CORS;
            } else if (!isValidOrigin(originHeader)) {
                requestType = CORSRequestType.INVALID_CORS;
            } else if (isLocalOrigin(request, originHeader)) {
                return CORSRequestType.NOT_CORS;
            } else {
                String method = request.getMethod();
                if (method != null) {
                    if ("OPTIONS".equals(method)) {
                        String accessControlRequestMethodHeader =
                                request.getHeader(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD);
                        if (accessControlRequestMethodHeader != null
                                && !accessControlRequestMethodHeader.isEmpty()) {
                            requestType = CORSRequestType.PRE_FLIGHT;
                        } else if (accessControlRequestMethodHeader != null
                                && accessControlRequestMethodHeader.isEmpty()) {
                            requestType = CORSRequestType.INVALID_CORS;
                        } else {
                            requestType = CORSRequestType.ACTUAL;
                        }
                    } else if ("GET".equals(method) || "HEAD".equals(method)) {
                        requestType = CORSRequestType.SIMPLE;
                    } else if ("POST".equals(method)) {
                        String mediaType = getMediaType(request.getContentType());
                        if (mediaType != null) {
                            if (SIMPLE_HTTP_REQUEST_CONTENT_TYPE_VALUES.contains(mediaType)) {
                                requestType = CORSRequestType.SIMPLE;
                            } else {
                                requestType = CORSRequestType.ACTUAL;
                            }
                        } else {
                            requestType = CORSRequestType.ACTUAL;
                        }
                    } else {
                        requestType = CORSRequestType.ACTUAL;
                    }
                }
            }
        } else {
            requestType = CORSRequestType.NOT_CORS;
        }

        return requestType;
    }
340634
def _get_response_mime_type(self):
        
        view_name = self.request.view_name
        if view_name != '':
            mime_type = get_registered_mime_type_for_name(view_name)
        else:
            mime_type = None
            acc = None
            for acc in self.request.accept:
                if acc == '*/*':
                    # The client does not care; use the default.
                    mime_type = self.__get_default_response_mime_type()
                    break
                try:
                    mime_type = \
                            get_registered_mime_type_for_string(acc.lower())
                except KeyError:
                    pass
                else:
                    break
            if mime_type is None:
                if not acc is None:
                    # The client specified a MIME type we can not handle; this
                    # is a 406 exception. We supply allowed MIME content
                    # types in the body of the response.
                    headers = \
                        [('Location', self.request.path_url),
                         ('Content-Type', TextPlainMime.mime_type_string),
                         ]
                    mime_strings = get_registered_mime_strings()
                    exc = HTTPNotAcceptable('Requested MIME content type(s) '
                                            'not acceptable.',
                                            body=','.join(mime_strings),
                                            headers=headers)
                    raise exc
                mime_type = self.__get_default_response_mime_type()
        return mime_type
146375
public static ScopedRequest unwrapRequest( ServletRequest request )
    {
        // Unwrap the multipart request, if there is one.
        if ( request instanceof MultipartRequestWrapper )
        {
            request = ( ( MultipartRequestWrapper ) request ).getRequest();
        }

        while ( request instanceof ServletRequestWrapper )
        {
            if ( request instanceof ScopedRequest )
            {
                return ( ScopedRequest ) request;
            }
            else
            {
                request = ( ( ServletRequestWrapper ) request ).getRequest();
            }
        }
        
        return null;
    }
1349971
private static String guessMimeTypeFromUri(final String uri) {
    final int questionmark = uri.indexOf('?', 1);  // 1 => skip the initial /
    final int end = (questionmark > 0 ? questionmark : uri.length()) - 1;
    if (end < 5) {  // Need at least: "/a.js"
      return null;
    }
    final char a = uri.charAt(end - 3);
    final char b = uri.charAt(end - 2);
    final char c = uri.charAt(end - 1);
    switch (uri.charAt(end)) {
      case 'g':
        return a == '.' && b == 'p' && c == 'n' ? "image/png" : null;
      case 'l':
        return a == 'h' && b == 't' && c == 'm' ? HTML_CONTENT_TYPE : null;
      case 's':
        if (a == '.' && b == 'c' && c == 's') {
          return "text/css";
        } else if (b == '.' && c == 'j') {
          return "text/javascript";
        } else {
          break;
        }
      case 'f':
        return a == '.' && b == 'g' && c == 'i' ? "image/gif" : null;
      case 'o':
        return a == '.' && b == 'i' && c == 'c' ? "image/x-icon" : null;
    }
    return null;
  }
251033
private String guessMimeType(final ChannelBuffer buf) {
    final String mimetype = guessMimeTypeFromUri(request().getUri());
    return mimetype == null ? guessMimeTypeFromContents(buf) : mimetype;
  }
1052471
private static String getContentTypeMime(final String httpContentType) {
        String mime = null;
        if (httpContentType != null) {
            final int i = httpContentType.indexOf(";");
            if (i == -1) {
                mime = httpContentType.trim();
            } else {
                mime = httpContentType.substring(0, i).trim();
            }
        }
        return mime;
    }
402731
public static void internalSetAndInitRequestScope (@Nonnull final IRequestScope aRequestScope)
  {
    ValueEnforcer.notNull (aRequestScope, "RequestScope");
    ValueEnforcer.isTrue (ScopeManager::isGlobalScopePresent,
                          "No global context present! May be the global context listener is not installed?");

    // Happens if an internal redirect happens in a web-application (e.g. for
    // 404 page)
    final IRequestScope aExistingRequestScope = s_aRequestScopeTL.get ();
    if (aExistingRequestScope != null)
    {
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("A request scope is already present - will overwrite it: " + aExistingRequestScope.toString ());
      if (aExistingRequestScope.isValid ())
      {
        // The scope shall be destroyed here, as this is most probably a
        // programming error!
        LOGGER.warn ("Destroying the old request scope before the new one gets initialized!");
        _destroyRequestScope (aExistingRequestScope);
      }
    }

    // set request context
    s_aRequestScopeTL.set (aRequestScope);

    // Now init the scope
    aRequestScope.initScope ();

    // call SPIs
    ScopeSPIManager.getInstance ().onRequestScopeBegin (aRequestScope);
  }
613238
public StringBuffer getRequestURL() {

		StringBuffer result = null;
		if(requestURL != null){
			result = new StringBuffer(requestURL);
		}
		
		return result;
	}
1341586
public void checkBrowserType(final HttpServletRequest request) {
    String reqpar = request.getParameter(getBrowserTypeRequestName());

    if (reqpar != null) {
      if (reqpar.equals("!")) {
        // Go back to unsticky browser type
        setBrowserTypeSticky(false);
      } else {
        setBrowserType(reqpar);
        setBrowserTypeSticky(false);
      }
    }

    reqpar = request.getParameter(getBrowserTypeStickyRequestName());
    if (reqpar != null) {
      if (reqpar.equals("!")) {
        // Go back to unsticky browser type
        setBrowserTypeSticky(false);
      } else {
        setBrowserType(reqpar);
        setBrowserTypeSticky(true);
      }
    }
  }
931996
private function checkRequestMime(Request $request, $requestMime)
    {
        if(empty($requestMime))
        {
            return true;
        }
        return Imi::checkCompareValues($requestMime, $request->getHeaderLine('Content-Type'));
    }
1285262
private static Single<Optional<String>> fetchAccessTokenAndReturnScope(UnitRequest request) {
        LOG.info("fetchAccessTokenAndReturnScope");
        String ip = request.getContext().getIp();
        if (StringUtil.isEmpty(ip)) {
            throw new IllegalArgumentException("Client's ip is empty, please check!");
        }
        if (isWhiteIp(ip)) {
            LOG.info(new JSONObject().fluentPut("type", LogTypeGateway.whiteIp)
                    .fluentPut("description", "request is from white ip " + ip)
                    .fluentPut("ip", ip));
            return Single.just(Optional.of(Scope.api_all));
        }
        String accessToken = request.getContext().getHeader() == null ? null :
                request.getContext().getHeader().getOrDefault(Constant.XIAN_REQUEST_TOKEN_HEADER, null);
        if (StringUtil.isEmpty(accessToken)) {
            return Single.just(Optional.empty());
        } else {
            return forToken(accessToken).map(optionalAccessToken -> {
                if (optionalAccessToken.isPresent()) {
                    request.getContext().setAccessToken(optionalAccessToken.get());
                    return Optional.of(optionalAccessToken.get().getScope());
                } else {
                    return Optional.empty();
                }
            });
        }
    }
312393
public static Object getScopedRequestAttribute( String attrName, ServletRequest request )
    {
        if ( request instanceof ScopedRequest )
        {
            return ( ( ScopedRequest ) request ).getAttribute( attrName, false );
        }
        
        return request.getAttribute( attrName );
    }
1324038
protected boolean isWeb() {
		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		if (attributes == null) {
			return false;
		}
		HttpServletRequest request = attributes.getRequest();
		if (request == null) {
			return false;
		}
		return true;
	}