1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Add a config option for HTTP timeout too

This commit is contained in:
SquidDev 2019-01-11 21:11:22 +00:00
parent 8dd084ac5c
commit 66b61d4e9e
4 changed files with 20 additions and 6 deletions

View File

@ -138,6 +138,7 @@ public class ComputerCraft
public static AddressPredicate http_whitelist = new AddressPredicate( DEFAULT_HTTP_WHITELIST );
public static AddressPredicate http_blacklist = new AddressPredicate( DEFAULT_HTTP_BLACKLIST );
public static int httpTimeout = 30000;
public static int httpMaxRequests = 16;
public static long httpMaxDownload = 16 * 1024 * 1024;
public static long httpMaxUpload = 4 * 1024 * 1024;

View File

@ -49,8 +49,6 @@ public class HttpRequest extends Resource<HttpRequest>
private static final int MAX_REDIRECTS = 16;
private static final int TIMEOUT = 30000;
private Future<?> executorFuture;
private ChannelFuture connectFuture;
private HttpRequestHandler currentRequest;
@ -160,15 +158,23 @@ private void doRequest( URI uri, HttpMethod method )
protected void initChannel( SocketChannel ch )
{
ch.config().setConnectTimeoutMillis( TIMEOUT );
if( ComputerCraft.httpTimeout > 0 )
{
ch.config().setConnectTimeoutMillis( ComputerCraft.httpTimeout );
}
ChannelPipeline p = ch.pipeline();
if( sslContext != null )
{
p.addLast( sslContext.newHandler( ch.alloc(), uri.getHost(), socketAddress.getPort() ) );
}
if( ComputerCraft.httpTimeout > 0 )
{
p.addLast( new ReadTimeoutHandler( ComputerCraft.httpTimeout, TimeUnit.MILLISECONDS ) );
}
p.addLast(
new ReadTimeoutHandler( TIMEOUT, TimeUnit.MILLISECONDS ),
new HttpClientCodec(),
new HttpContentDecompressor(),
handler

View File

@ -50,6 +50,7 @@ public class Config
private static Property httpWhitelist;
private static Property httpBlacklist;
private static Property httpTimeout;
private static Property httpMaxRequests;
private static Property httpMaxDownload;
private static Property httpMaxUpload;
@ -142,6 +143,10 @@ public static void load( File configFile )
"If this is empty then all whitelisted domains will be accessible. Example: \"*.github.com\" will block access to all subdomains of github.com.\n" +
"You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." );
httpTimeout = config.get( CATEGORY_HTTP, "timeout", ComputerCraft.httpTimeout );
httpTimeout.setComment( "The period of time (in milliseconds) to wait before a HTTP request times out. Set to 0 for unlimited." );
httpTimeout.setMinValue( 0 );
httpMaxRequests = config.get( CATEGORY_HTTP, "max_requests", ComputerCraft.httpMaxRequests );
httpMaxRequests.setComment( "The number of http requests a computer can make at one time. Additional requests will be queued, and sent when the running requests have finished. Set to 0 for unlimited." );
httpMaxRequests.setMinValue( 0 );
@ -166,7 +171,7 @@ public static void load( File configFile )
setOrder(
CATEGORY_HTTP,
httpEnable, httpWebsocketEnable, httpWhitelist, httpBlacklist,
httpMaxRequests, httpMaxDownload, httpMaxUpload, httpMaxWebsockets, httpMaxWebsocketMessage
httpTimeout, httpMaxRequests, httpMaxDownload, httpMaxUpload, httpMaxWebsockets, httpMaxWebsocketMessage
);
}
@ -282,7 +287,7 @@ private static void setupLanguage( ConfigCategory category, String key )
category.setLanguageKey( key );
for( Property property : category.getOrderedValues() )
{
property.setLanguageKey( key + "." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
property.setLanguageKey( key + "." + property.getName() );
}
for( ConfigCategory child : category.getChildren() )
@ -315,6 +320,7 @@ public static void sync()
ComputerCraft.http_whitelist = new AddressPredicate( httpWhitelist.getStringList() );
ComputerCraft.http_blacklist = new AddressPredicate( httpBlacklist.getStringList() );
ComputerCraft.httpTimeout = Math.max( 0, httpTimeout.getInt() );
ComputerCraft.httpMaxRequests = Math.max( 1, httpMaxRequests.getInt() );
ComputerCraft.httpMaxDownload = Math.max( 0, httpMaxDownload.getLong() );
ComputerCraft.httpMaxUpload = Math.max( 0, httpMaxUpload.getLong() );

View File

@ -59,6 +59,7 @@ gui.computercraft:config.http.websocket_enabled=Enable websockets
gui.computercraft:config.http.whitelist=HTTP whitelist
gui.computercraft:config.http.blacklist=HTTP blacklist
gui.computercraft:config.http.timeout=Timeout
gui.computercraft:config.http.max_requests=Maximum concurrent requests
gui.computercraft:config.http.max_download=Maximum response size
gui.computercraft:config.http.max_upload=Maximum request