Path: blob/master/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerConfig.java
41159 views
/*1* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.net.httpserver;2627import java.lang.System.Logger;28import java.lang.System.Logger.Level;29import java.security.PrivilegedAction;3031/**32* Parameters that users will not likely need to set33* but are useful for debugging34*/3536@SuppressWarnings("removal")37class ServerConfig {3839private static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.4041/* These values must be a reasonable multiple of clockTick */42private static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min43private static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;4445private static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever46private static final long DEFAULT_MAX_RSP_TIME = -1; // default: forever47private static final long DEFAULT_TIMER_MILLIS = 1000;48private static final int DEFAULT_MAX_REQ_HEADERS = 200;49private static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024;5051private static int clockTick;52private static long idleInterval;53// The maximum number of bytes to drain from an inputstream54private static long drainAmount;55private static int maxIdleConnections;56// The maximum number of request headers allowable57private static int maxReqHeaders;58// max time a request or response is allowed to take59private static long maxReqTime;60private static long maxRspTime;61private static long timerMillis;62private static boolean debug;6364// the value of the TCP_NODELAY socket-level option65private static boolean noDelay;6667static {68java.security.AccessController.doPrivileged(69new PrivilegedAction<Void>() {70@Override71public Void run () {72idleInterval = Long.getLong("sun.net.httpserver.idleInterval",73DEFAULT_IDLE_INTERVAL) * 1000;7475clockTick = Integer.getInteger("sun.net.httpserver.clockTick",76DEFAULT_CLOCK_TICK);7778maxIdleConnections = Integer.getInteger(79"sun.net.httpserver.maxIdleConnections",80DEFAULT_MAX_IDLE_CONNECTIONS);8182drainAmount = Long.getLong("sun.net.httpserver.drainAmount",83DEFAULT_DRAIN_AMOUNT);8485maxReqHeaders = Integer.getInteger(86"sun.net.httpserver.maxReqHeaders",87DEFAULT_MAX_REQ_HEADERS);8889maxReqTime = Long.getLong("sun.net.httpserver.maxReqTime",90DEFAULT_MAX_REQ_TIME);9192maxRspTime = Long.getLong("sun.net.httpserver.maxRspTime",93DEFAULT_MAX_RSP_TIME);9495timerMillis = Long.getLong("sun.net.httpserver.timerMillis",96DEFAULT_TIMER_MILLIS);9798debug = Boolean.getBoolean("sun.net.httpserver.debug");99100noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay");101102return null;103}104});105106}107108static void checkLegacyProperties(final Logger logger) {109110// legacy properties that are no longer used111// print a warning to logger if they are set.112113java.security.AccessController.doPrivileged(114new PrivilegedAction<Void>() {115public Void run () {116if (System.getProperty("sun.net.httpserver.readTimeout")117!=null)118{119logger.log (Level.WARNING,120"sun.net.httpserver.readTimeout "+121"property is no longer used. "+122"Use sun.net.httpserver.maxReqTime instead."123);124}125if (System.getProperty("sun.net.httpserver.writeTimeout")126!=null)127{128logger.log (Level.WARNING,129"sun.net.httpserver.writeTimeout "+130"property is no longer used. Use "+131"sun.net.httpserver.maxRspTime instead."132);133}134if (System.getProperty("sun.net.httpserver.selCacheTimeout")135!=null)136{137logger.log (Level.WARNING,138"sun.net.httpserver.selCacheTimeout "+139"property is no longer used."140);141}142return null;143}144}145);146}147148static boolean debugEnabled() {149return debug;150}151152static long getIdleInterval() {153return idleInterval;154}155156static int getClockTick() {157return clockTick;158}159160static int getMaxIdleConnections() {161return maxIdleConnections;162}163164static long getDrainAmount() {165return drainAmount;166}167168static int getMaxReqHeaders() {169return maxReqHeaders;170}171172static long getMaxReqTime() {173return maxReqTime;174}175176static long getMaxRspTime() {177return maxRspTime;178}179180static long getTimerMillis() {181return timerMillis;182}183184static boolean noDelay() {185return noDelay;186}187}188189190