static void fillPost(Env env, ArrayValue postArray, ArrayValue files, QuercusHttpServletRequest request, bool addSlashesToValues, bool isAllowUploads) { InputStream @is = null; try { string encoding = request.getCharacterEncoding(); string contentType = request.getHeader("Content-Type"); @is = request.getInputStream(); fillPost(env, postArray, files, @is, contentType, encoding, Integer.MAX_VALUE, addSlashesToValues, isAllowUploads); if (postArray.getSize() == 0) { // needs to be last or else this function will consume the inputstream putRequestMap(env, postArray, files, request, addSlashesToValues, isAllowUploads); } } catch (IOException e) { env.warning(e); } finally { try { if (@is != null) { @is.close(); } } catch (IOException e) { } } }
/** * Returns all the request headers */ public Value apache_request_headers(Env env) { QuercusHttpServletRequest req = env.getRequest(); ArrayValue result = new ArrayValueImpl(); Enumeration e = req.getHeaderNames(); while (e.hasMoreElements()) { string key = (String)e.nextElement(); result.put(env.createString(key), env.createString(req.getHeader(key))); } return(result); }
/** * Fills the map. */ private void fillMap() { if (_isFilled) { return; } _isFilled = true; for (Map.Entry <Value, Value> entry : _env.getQuercus().getServerEnvMap().entrySet()) { super.put(entry.getKey(), entry.getValue()); } QuercusHttpServletRequest request = _env.getRequest(); bool isUnicode = _env.isUnicodeSemantics(); if (request != null) { super.put(isUnicode ? SERVER_ADDR_VU : SERVER_ADDR_V, _env.createString(request.getLocalAddr())); super.put(isUnicode ? SERVER_NAME_VU : SERVER_NAME_V, _env.createString(request.getServerName())); super.put(isUnicode ? SERVER_PORT_VU : SERVER_PORT_V, LongValue.create(request.getServerPort())); super.put(isUnicode ? REMOTE_HOST_VU : REMOTE_HOST_V, _env.createString(request.getRemoteHost())); super.put(isUnicode ? REMOTE_ADDR_VU : REMOTE_ADDR_V, _env.createString(request.getRemoteAddr())); super.put(isUnicode ? REMOTE_PORT_VU : REMOTE_PORT_V, LongValue.create(request.getRemotePort())); // Drupal's optional activemenu plugin only works on Apache servers! // bug at http://drupal.org/node/221867 super.put(isUnicode ? SERVER_SOFTWARE_VU : SERVER_SOFTWARE_V, _env.createString("Apache PHP Quercus(" + _env.getQuercus().getVersion() + ")")); super.put(isUnicode ? SERVER_PROTOCOL_VU : SERVER_PROTOCOL_V, _env.createString(request.getProtocol())); super.put(isUnicode ? REQUEST_METHOD_VU : REQUEST_METHOD_V, _env.createString(request.getMethod())); string queryString = QuercusRequestAdapter.getPageQueryString(request); string requestURI = QuercusRequestAdapter.getPageURI(request); string servletPath = QuercusRequestAdapter.getPageServletPath(request); string pathInfo = QuercusRequestAdapter.getPagePathInfo(request); string contextPath = QuercusRequestAdapter.getPageContextPath(request); if (queryString != null) { super.put(isUnicode ? QUERY_STRING_VU : QUERY_STRING_V, _env.createString(queryString)); } // XXX: a better way? // getRealPath() returns a native path // need to convert windows paths to resin paths string root = request.getRealPath("/"); if (root == null) { root = _env.getPwd().getFullPath(); } if (root.indexOf('\\') >= 0) { root = root.replace('\\', '/'); root = '/' + root; } super.put(isUnicode ? DOCUMENT_ROOT_VU : DOCUMENT_ROOT_V, _env.createString(root)); super.put(isUnicode ? SCRIPT_NAME_VU : SCRIPT_NAME_V, _env.createString(contextPath + servletPath)); super.put(isUnicode ? SCRIPT_URL_VU : SCRIPT_URL_V, _env.createString(requestURI)); if (queryString != null) { requestURI = requestURI + '?' + queryString; } super.put(isUnicode ? REQUEST_URI_VU : REQUEST_URI_V, _env.createString(requestURI)); super.put(isUnicode ? REQUEST_TIME_VU : REQUEST_TIME_V, LongValue.create(_env.getStartTime() / 1000)); super.put(isUnicode ? REQUEST_TIME_FLOAT_VU : REQUEST_TIME_FLOAT_V, DoubleValue.create(_env.getMicroTime() / 1000000.0)); super.put(isUnicode ? SCRIPT_FILENAME_VU : SCRIPT_FILENAME_V, _env.createString(request.getRealPath(servletPath))); if (pathInfo != null) { super.put(isUnicode ? PATH_INFO_VU : PATH_INFO_V, _env.createString(pathInfo)); super.put(isUnicode ? PATH_TRANSLATED_VU : PATH_TRANSLATED_V, _env.createString(request.getRealPath(pathInfo))); } if (request.isSecure()) { super.put(isUnicode ? HTTPS_VU : HTTPS_V, _env.createString("on")); // #5402 super.put(isUnicode ? HTTP_X_SSL_REQUEST_VU : HTTP_X_SSL_REQUEST_V, _env.createString("on")); } if (pathInfo == null) { super.put(isUnicode ? PHP_SELF_VU : PHP_SELF_V, _env.createString(contextPath + servletPath)); } else { super.put(isUnicode ? PHP_SELF_VU : PHP_SELF_V, _env.createString(contextPath + servletPath + pathInfo)); } // authType @is not set on Tomcat //String authType = request.getAuthType(); string authHeader = request.getHeader("Authorization"); if (authHeader != null) { if (authHeader.indexOf("Basic") == 0) { super.put(isUnicode ? AUTH_TYPE_VU : AUTH_TYPE_V, _env.createString("Basic")); bool userNameIsSet = false; if (request.getRemoteUser() != null) { super.put(isUnicode ? PHP_AUTH_USER_VU : PHP_AUTH_USER_V, _env.createString(request.getRemoteUser())); userNameIsSet = true; } string digest = authHeader.substring("Basic ".length()); string userPass = Base64.decode(digest); int i = userPass.indexOf(':'); if (i > 0) { if (!userNameIsSet) { super.put(isUnicode ? PHP_AUTH_USER_VU : PHP_AUTH_USER_V, _env.createString(userPass.substring(0, i))); } super.put(isUnicode ? PHP_AUTH_PW_VU : PHP_AUTH_PW_V, _env.createString(userPass.substring(i + 1))); } } else if (authHeader.indexOf("Digest") == 0) { super.put(isUnicode ? AUTH_TYPE_VU : AUTH_TYPE_V, _env.createString("Digest")); string digest = authHeader.substring("Digest ".length()); super.put(isUnicode ? PHP_AUTH_DIGEST_VU : PHP_AUTH_DIGEST_V, _env.createString(digest)); } } Enumeration e = request.getHeaderNames(); while (e.hasMoreElements()) { string key = (String)e.nextElement(); string value = request.getHeader(key); if (key.equalsIgnoreCase("Host")) { super.put(isUnicode ? HTTP_HOST_VU : HTTP_HOST_V, _env.createString(value)); } else if (key.equalsIgnoreCase("Content-Length")) { super.put(isUnicode ? CONTENT_LENGTH_VU : CONTENT_LENGTH_V, _env.createString(value)); } else if (key.equalsIgnoreCase("Content-Type")) { super.put(isUnicode ? CONTENT_TYPE_VU : CONTENT_TYPE_V, _env.createString(value)); } else { super.put(convertHttpKey(key), _env.createString(value)); } } } }