author | asaha |
Fri, 24 Feb 2012 17:31:59 -0800 | |
changeset 11916 | d64a0627d990 |
parent 11902 | a94ba35d9c4a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
2 |
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.net.httpserver; |
|
27 |
||
7271 | 28 |
import java.util.logging.Logger; |
29 |
import java.security.PrivilegedAction; |
|
2 | 30 |
|
31 |
/** |
|
32 |
* Parameters that users will not likely need to set |
|
33 |
* but are useful for debugging |
|
34 |
*/ |
|
35 |
||
36 |
class ServerConfig { |
|
37 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
38 |
private static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec. |
2 | 39 |
|
40 |
/* These values must be a reasonable multiple of clockTick */ |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
41 |
private static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
42 |
private static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ; |
2 | 43 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
44 |
private static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
45 |
private static final long DEFAULT_MAX_RSP_TIME = -1; // default: forever |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
46 |
private static final long DEFAULT_TIMER_MILLIS = 1000; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
47 |
private static final int DEFAULT_MAX_REQ_HEADERS = 200; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
48 |
private static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024; |
7271 | 49 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
50 |
private static int clockTick; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
51 |
private static long idleInterval; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
52 |
// The maximum number of bytes to drain from an inputstream |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
53 |
private static long drainAmount; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
54 |
private static int maxIdleConnections; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
55 |
// The maximum number of request headers allowable |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
56 |
private static int maxReqHeaders; |
7271 | 57 |
// max time a request or response is allowed to take |
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
58 |
private static long maxReqTime; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
59 |
private static long maxRspTime; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
60 |
private static long timerMillis; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
61 |
private static boolean debug; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
62 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
63 |
// the value of the TCP_NODELAY socket-level option |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
64 |
private static boolean noDelay; |
2 | 65 |
|
66 |
static { |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
67 |
java.security.AccessController.doPrivileged( |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
68 |
new PrivilegedAction<Void>() { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
69 |
@Override |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
70 |
public Void run () { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
71 |
idleInterval = Long.getLong("sun.net.httpserver.idleInterval", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
72 |
DEFAULT_IDLE_INTERVAL) * 1000; |
2 | 73 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
74 |
clockTick = Integer.getInteger("sun.net.httpserver.clockTick", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
75 |
DEFAULT_CLOCK_TICK); |
2 | 76 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
77 |
maxIdleConnections = Integer.getInteger( |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
78 |
"sun.net.httpserver.maxIdleConnections", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
79 |
DEFAULT_MAX_IDLE_CONNECTIONS); |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
80 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
81 |
drainAmount = Long.getLong("sun.net.httpserver.drainAmount", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
82 |
DEFAULT_DRAIN_AMOUNT); |
2 | 83 |
|
11916
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
84 |
maxReqHeaders = Integer.getInteger( |
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
85 |
"sun.net.httpserver.maxReqHeaders", |
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
86 |
DEFAULT_MAX_REQ_HEADERS); |
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
87 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
88 |
maxReqTime = Long.getLong("sun.net.httpserver.maxReqTime", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
89 |
DEFAULT_MAX_REQ_TIME); |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
90 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
91 |
maxRspTime = Long.getLong("sun.net.httpserver.maxRspTime", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
92 |
DEFAULT_MAX_RSP_TIME); |
7271 | 93 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
94 |
timerMillis = Long.getLong("sun.net.httpserver.timerMillis", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
95 |
DEFAULT_TIMER_MILLIS); |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
96 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
97 |
debug = Boolean.getBoolean("sun.net.httpserver.debug"); |
7271 | 98 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
99 |
noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay"); |
2 | 100 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
101 |
return null; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
102 |
} |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
103 |
}); |
2 | 104 |
|
105 |
} |
|
106 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
107 |
static void checkLegacyProperties(final Logger logger) { |
7271 | 108 |
|
109 |
// legacy properties that are no longer used |
|
110 |
// print a warning to logger if they are set. |
|
2 | 111 |
|
7271 | 112 |
java.security.AccessController.doPrivileged( |
113 |
new PrivilegedAction<Void>() { |
|
114 |
public Void run () { |
|
115 |
if (System.getProperty("sun.net.httpserver.readTimeout") |
|
116 |
!=null) |
|
117 |
{ |
|
118 |
logger.warning ("sun.net.httpserver.readTimeout "+ |
|
119 |
"property is no longer used. "+ |
|
120 |
"Use sun.net.httpserver.maxReqTime instead." |
|
121 |
); |
|
122 |
} |
|
123 |
if (System.getProperty("sun.net.httpserver.writeTimeout") |
|
124 |
!=null) |
|
125 |
{ |
|
126 |
logger.warning ("sun.net.httpserver.writeTimeout "+ |
|
127 |
"property is no longer used. Use "+ |
|
128 |
"sun.net.httpserver.maxRspTime instead." |
|
129 |
); |
|
130 |
} |
|
131 |
if (System.getProperty("sun.net.httpserver.selCacheTimeout") |
|
132 |
!=null) |
|
133 |
{ |
|
134 |
logger.warning ("sun.net.httpserver.selCacheTimeout "+ |
|
135 |
"property is no longer used." |
|
136 |
); |
|
137 |
} |
|
138 |
return null; |
|
139 |
} |
|
140 |
} |
|
141 |
); |
|
2 | 142 |
} |
143 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
144 |
static boolean debugEnabled() { |
2 | 145 |
return debug; |
146 |
} |
|
147 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
148 |
static long getIdleInterval() { |
2 | 149 |
return idleInterval; |
150 |
} |
|
151 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
152 |
static int getClockTick() { |
2 | 153 |
return clockTick; |
154 |
} |
|
155 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
156 |
static int getMaxIdleConnections() { |
2 | 157 |
return maxIdleConnections; |
158 |
} |
|
159 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
160 |
static long getDrainAmount() { |
2 | 161 |
return drainAmount; |
162 |
} |
|
7271 | 163 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
164 |
static int getMaxReqHeaders() { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
165 |
return maxReqHeaders; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
166 |
} |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
167 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
168 |
static long getMaxReqTime() { |
7271 | 169 |
return maxReqTime; |
170 |
} |
|
171 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
172 |
static long getMaxRspTime() { |
7271 | 173 |
return maxRspTime; |
174 |
} |
|
175 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
176 |
static long getTimerMillis() { |
7271 | 177 |
return timerMillis; |
178 |
} |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
179 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
180 |
static boolean noDelay() { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
181 |
return noDelay; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
182 |
} |
2 | 183 |
} |