author | ssadetsky |
Mon, 16 Oct 2017 08:06:56 -0700 | |
changeset 47387 | 4d711a58bb3b |
parent 47216 | 71c04702a3d5 |
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 |
||
41592
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
28 |
import java.lang.System.Logger; |
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
29 |
import java.lang.System.Logger.Level; |
7271 | 30 |
import java.security.PrivilegedAction; |
2 | 31 |
|
32 |
/** |
|
33 |
* Parameters that users will not likely need to set |
|
34 |
* but are useful for debugging |
|
35 |
*/ |
|
36 |
||
37 |
class ServerConfig { |
|
38 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
39 |
private static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec. |
2 | 40 |
|
41 |
/* 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
|
42 |
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
|
43 |
private static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ; |
2 | 44 |
|
11901
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_REQ_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_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
|
47 |
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
|
48 |
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
|
49 |
private static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024; |
7271 | 50 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
51 |
private static int clockTick; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
52 |
private static long idleInterval; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
53 |
// 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
|
54 |
private static long drainAmount; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
55 |
private static int maxIdleConnections; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
56 |
// 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
|
57 |
private static int maxReqHeaders; |
7271 | 58 |
// 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
|
59 |
private static long maxReqTime; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
60 |
private static long maxRspTime; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
61 |
private static long timerMillis; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
62 |
private static boolean debug; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
63 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
64 |
// 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
|
65 |
private static boolean noDelay; |
2 | 66 |
|
67 |
static { |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
68 |
java.security.AccessController.doPrivileged( |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
69 |
new PrivilegedAction<Void>() { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
70 |
@Override |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
71 |
public Void run () { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
72 |
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
|
73 |
DEFAULT_IDLE_INTERVAL) * 1000; |
2 | 74 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
75 |
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
|
76 |
DEFAULT_CLOCK_TICK); |
2 | 77 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
78 |
maxIdleConnections = Integer.getInteger( |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
79 |
"sun.net.httpserver.maxIdleConnections", |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
80 |
DEFAULT_MAX_IDLE_CONNECTIONS); |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
81 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
82 |
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
|
83 |
DEFAULT_DRAIN_AMOUNT); |
2 | 84 |
|
11916
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
85 |
maxReqHeaders = Integer.getInteger( |
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
86 |
"sun.net.httpserver.maxReqHeaders", |
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
87 |
DEFAULT_MAX_REQ_HEADERS); |
d64a0627d990
7148758: Resolve merge issue which caused testcase failure
asaha
parents:
11902
diff
changeset
|
88 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
89 |
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
|
90 |
DEFAULT_MAX_REQ_TIME); |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
91 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
92 |
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
|
93 |
DEFAULT_MAX_RSP_TIME); |
7271 | 94 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
95 |
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
|
96 |
DEFAULT_TIMER_MILLIS); |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
97 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
98 |
debug = Boolean.getBoolean("sun.net.httpserver.debug"); |
7271 | 99 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
100 |
noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay"); |
2 | 101 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
102 |
return null; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
103 |
} |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
104 |
}); |
2 | 105 |
|
106 |
} |
|
107 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
108 |
static void checkLegacyProperties(final Logger logger) { |
7271 | 109 |
|
110 |
// legacy properties that are no longer used |
|
111 |
// print a warning to logger if they are set. |
|
2 | 112 |
|
7271 | 113 |
java.security.AccessController.doPrivileged( |
114 |
new PrivilegedAction<Void>() { |
|
115 |
public Void run () { |
|
116 |
if (System.getProperty("sun.net.httpserver.readTimeout") |
|
117 |
!=null) |
|
118 |
{ |
|
41592
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
119 |
logger.log (Level.WARNING, |
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
120 |
"sun.net.httpserver.readTimeout "+ |
7271 | 121 |
"property is no longer used. "+ |
122 |
"Use sun.net.httpserver.maxReqTime instead." |
|
123 |
); |
|
124 |
} |
|
125 |
if (System.getProperty("sun.net.httpserver.writeTimeout") |
|
126 |
!=null) |
|
127 |
{ |
|
41592
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
128 |
logger.log (Level.WARNING, |
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
129 |
"sun.net.httpserver.writeTimeout "+ |
7271 | 130 |
"property is no longer used. Use "+ |
131 |
"sun.net.httpserver.maxRspTime instead." |
|
132 |
); |
|
133 |
} |
|
134 |
if (System.getProperty("sun.net.httpserver.selCacheTimeout") |
|
135 |
!=null) |
|
136 |
{ |
|
41592
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
137 |
logger.log (Level.WARNING, |
855537e5ad9c
8157965: update httpserver logging to use java.lang.System.Logger
dfuchs
parents:
25859
diff
changeset
|
138 |
"sun.net.httpserver.selCacheTimeout "+ |
7271 | 139 |
"property is no longer used." |
140 |
); |
|
141 |
} |
|
142 |
return null; |
|
143 |
} |
|
144 |
} |
|
145 |
); |
|
2 | 146 |
} |
147 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
148 |
static boolean debugEnabled() { |
2 | 149 |
return debug; |
150 |
} |
|
151 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
152 |
static long getIdleInterval() { |
2 | 153 |
return idleInterval; |
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 getClockTick() { |
2 | 157 |
return clockTick; |
158 |
} |
|
159 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
160 |
static int getMaxIdleConnections() { |
2 | 161 |
return maxIdleConnections; |
162 |
} |
|
163 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
164 |
static long getDrainAmount() { |
2 | 165 |
return drainAmount; |
166 |
} |
|
7271 | 167 |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
168 |
static int getMaxReqHeaders() { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
169 |
return maxReqHeaders; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
170 |
} |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
171 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
172 |
static long getMaxReqTime() { |
7271 | 173 |
return maxReqTime; |
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 getMaxRspTime() { |
7271 | 177 |
return maxRspTime; |
178 |
} |
|
179 |
||
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
180 |
static long getTimerMillis() { |
7271 | 181 |
return timerMillis; |
182 |
} |
|
11901
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
183 |
|
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
184 |
static boolean noDelay() { |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
185 |
return noDelay; |
d7f004398a91
7126960: Add property to limit number of request headers to the HTTP Server
chegar
parents:
7668
diff
changeset
|
186 |
} |
2 | 187 |
} |