Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions common/src/main/java/com/taobao/arthas/common/ArthasConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ public class ArthasConstants {

public static final int MAX_HTTP_CONTENT_LENGTH = 1024 * 1024 * 10;

/**
* System property to override the max HTTP content length used by the
* tunnel-client when proxying responses (e.g. JFR recording downloads)
* back to the tunnel-server. The value is in bytes; default is
* {@link #MAX_HTTP_CONTENT_LENGTH} (10 MB). See issue #3034.
*/
public static final String TUNNEL_CLIENT_MAX_HTTP_CONTENT_LENGTH_PROPERTY = "arthas.tunnel.client.max-http-content-length";

/**
* Resolve the configured tunnel-client max HTTP content length. Falls back
* to {@link #MAX_HTTP_CONTENT_LENGTH} when the system property is unset,
* non-numeric, or non-positive.
*/
public static int getTunnelClientMaxHttpContentLength() {
String value = System.getProperty(TUNNEL_CLIENT_MAX_HTTP_CONTENT_LENGTH_PROPERTY);
if (value == null || value.isEmpty()) {
return MAX_HTTP_CONTENT_LENGTH;
}
try {
int parsed = Integer.parseInt(value.trim());
if (parsed > 0) {
return parsed;
}
} catch (NumberFormatException ignore) {
// fall through to default
}
return MAX_HTTP_CONTENT_LENGTH;
}

public static final String ARTHAS_OUTPUT = "arthas-output";

public static final String APP_NAME = "app-name";
Expand Down
10 changes: 10 additions & 0 deletions tunnel-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
<artifactId>netty-codec-http</artifactId>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public SimpleHttpResponse query(String targetUrl) throws InterruptedException {
@Override
protected void initChannel(LocalChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpClientCodec(), new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH),
p.addLast(new HttpClientCodec(),
new HttpObjectAggregator(ArthasConstants.getTunnelClientMaxHttpContentLength()),
new HttpProxyClientHandler(httpResponsePromise));
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.taobao.arthas.common;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* Tests for the configurable tunnel-client max HTTP content length introduced
* for issue #3034 ("Unable to download JFR recordings larger than 10MB via
* Tunnel Server").
*/
public class ArthasConstantsTest {

private static final String PROPERTY = ArthasConstants.TUNNEL_CLIENT_MAX_HTTP_CONTENT_LENGTH_PROPERTY;

private String originalValue;

@Before
public void saveProperty() {
originalValue = System.getProperty(PROPERTY);
System.clearProperty(PROPERTY);
}

@After
public void restoreProperty() {
if (originalValue == null) {
System.clearProperty(PROPERTY);
} else {
System.setProperty(PROPERTY, originalValue);
}
}

@Test
public void defaultsToTenMegabytesWhenPropertyMissing() {
assertEquals(ArthasConstants.MAX_HTTP_CONTENT_LENGTH,
ArthasConstants.getTunnelClientMaxHttpContentLength());
}

@Test
public void honoursConfiguredPropertyValue() {
int oneHundredMb = 100 * 1024 * 1024;
System.setProperty(PROPERTY, Integer.toString(oneHundredMb));

assertEquals(oneHundredMb, ArthasConstants.getTunnelClientMaxHttpContentLength());
}

@Test
public void fallsBackToDefaultWhenPropertyIsNotANumber() {
System.setProperty(PROPERTY, "not-a-number");

assertEquals(ArthasConstants.MAX_HTTP_CONTENT_LENGTH,
ArthasConstants.getTunnelClientMaxHttpContentLength());
}

@Test
public void fallsBackToDefaultWhenPropertyIsNotPositive() {
System.setProperty(PROPERTY, "0");
assertEquals(ArthasConstants.MAX_HTTP_CONTENT_LENGTH,
ArthasConstants.getTunnelClientMaxHttpContentLength());

System.setProperty(PROPERTY, "-1");
assertEquals(ArthasConstants.MAX_HTTP_CONTENT_LENGTH,
ArthasConstants.getTunnelClientMaxHttpContentLength());
}
}
Loading