Skip to content

Commit d65f064

Browse files
committed
don't invoke getInputStream and getReader in HttpServletRequestWrapper twice; add several methods of HttpServletRequestWrapper
1 parent 9eb44ce commit d65f064

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

framework/src/main/java/org/tron/core/services/filter/BufferedResponseWrapper.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,42 @@ public void setContentLengthLong(long len) {
101101
}
102102
}
103103

104+
@Override
105+
public int getStatus() {
106+
return this.status;
107+
}
108+
104109
@Override
105110
public void setStatus(int sc) {
106111
this.status = sc;
107112
}
108113

114+
@Override
115+
public void setHeader(String name, String value) {
116+
if ("content-length".equalsIgnoreCase(name)) {
117+
try {
118+
setContentLengthLong(Long.parseLong(value));
119+
} catch (NumberFormatException ignored) {
120+
// malformed value, skip overflow check
121+
}
122+
} else {
123+
super.setHeader(name, value);
124+
}
125+
}
126+
127+
@Override
128+
public void addHeader(String name, String value) {
129+
if ("content-length".equalsIgnoreCase(name)) {
130+
try {
131+
setContentLengthLong(Long.parseLong(value));
132+
} catch (NumberFormatException ignored) {
133+
// malformed value, skip overflow check
134+
}
135+
} else {
136+
super.addHeader(name, value);
137+
}
138+
}
139+
109140
@Override
110141
public void setContentType(String type) {
111142
this.contentType = type;

framework/src/main/java/org/tron/core/services/filter/CachedBodyRequestWrapper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
public class CachedBodyRequestWrapper extends HttpServletRequestWrapper {
1717

18+
private enum BodyAccessor { NONE, STREAM, READER }
19+
1820
private final byte[] body;
21+
private BodyAccessor accessor = BodyAccessor.NONE;
1922

2023
public CachedBodyRequestWrapper(HttpServletRequest request, byte[] body) {
2124
super(request);
@@ -24,6 +27,10 @@ public CachedBodyRequestWrapper(HttpServletRequest request, byte[] body) {
2427

2528
@Override
2629
public ServletInputStream getInputStream() {
30+
if (accessor == BodyAccessor.READER) {
31+
throw new IllegalStateException("getReader() has already been called on this request");
32+
}
33+
accessor = BodyAccessor.STREAM;
2734
final ByteArrayInputStream bais = new ByteArrayInputStream(body);
2835
return new ServletInputStream() {
2936
@Override
@@ -54,6 +61,10 @@ public void setReadListener(ReadListener readListener) {
5461

5562
@Override
5663
public BufferedReader getReader() {
64+
if (accessor == BodyAccessor.STREAM) {
65+
throw new IllegalStateException("getInputStream() has already been called on this request");
66+
}
67+
accessor = BodyAccessor.READER;
5768
String encoding = getCharacterEncoding();
5869
Charset charset = encoding != null ? Charset.forName(encoding) : StandardCharsets.UTF_8;
5970
return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(body), charset));

framework/src/main/resources/config.conf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,17 @@ node {
366366
# httpPBFTEnable = false
367367
# httpPBFTPort = 8565
368368

369-
# The maximum blocks range to retrieve logs for eth_getLogs, default: 5000, >0 otherwise no limit
369+
# The maximum blocks range to retrieve logs for eth_getLogs, default: 5000, <=0 means no limit
370370
maxBlockRange = 5000
371-
# Allowed max address count in filter request, default: 1000, >0 otherwise no limit
371+
# Allowed max address count in filter request, default: 1000, <=0 means no limit
372372
maxAddressSize = 1000
373-
# The maximum number of allowed topics within a topic criteria, default: 1000, >0 otherwise no limit
373+
# The maximum number of allowed topics within a topic criteria, default: 1000, <=0 means no limit
374374
maxSubTopics = 1000
375-
# Allowed maximum number for blockFilter, default: 50000, >0 otherwise no limit
375+
# Allowed maximum number for blockFilter, default: 50000, <=0 means no limit
376376
maxBlockFilterNum = 50000
377-
# Allowed batch size, default: 100, >0 otherwise no limit
377+
# Allowed batch size, default: 100, <=0 means no limit
378378
maxBatchSize = 100
379-
# Allowed max response byte size, default: 26214400 (25 MB), >0 otherwise no limit
379+
# Allowed max response byte size, default: 26214400 (25 MB), <=0 means no limit
380380
maxResponseSize = 26214400
381381
}
382382

0 commit comments

Comments
 (0)