Skip to content

Commit

Permalink
Added ability to clone servers
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Aug 29, 2013
1 parent ae12596 commit 79235be
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 174 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ HttpProxyServer server =
.start();
```

If you want to create additional proxy servers with similar configuration but
listening on different ports, you can clone an existing server. The cloned
servers will share event loops to reduce resource usage and when one clone is
stopped, all are stopped.

```
existingServer.clone().withPort(8081).start()
```

If you have questions, please visit our Google Group here:

https://groups.google.com/forum/#!forum/littleproxy
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/org/littleshoot/proxy/HttpProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@
*/
public interface HttpProxyServer {

int getIdleConnectionTimeout();

void setIdleConnectionTimeout(int idleConnectionTimeout);

/**
* <p>
* Clone the existing server, with a port 1 higher and everything else the
* same.
* </p>
*
* <p>
* The new server will share event loops with the original server.
* </p>
*
* @return a bootstrap that allows customizing and starting the cloned
* server
*/
HttpProxyServerBootstrap clone();

/**
* Stops the server.
* Stops the server and all related clones.
*/
void stop();

Expand Down
56 changes: 56 additions & 0 deletions src/main/java/org/littleshoot/proxy/HttpProxyServerBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.littleshoot.proxy;

public interface HttpProxyServerBootstrap {

public abstract HttpProxyServerBootstrap withTransportProtocol(
TransportProtocol transportProtocol);

public abstract HttpProxyServerBootstrap withPort(int port);

public abstract HttpProxyServerBootstrap withSslContextSource(
SSLContextSource sslContextSource);

public abstract HttpProxyServerBootstrap withProxyAuthenticator(
ProxyAuthenticator proxyAuthenticator);

public abstract HttpProxyServerBootstrap withChainProxyManager(
ChainedProxyManager chainProxyManager);

public abstract HttpProxyServerBootstrap withRequestFilter(
HttpRequestFilter requestFilter);

public abstract HttpProxyServerBootstrap withResponseFilters(
HttpResponseFilters responseFilters);

public abstract HttpProxyServerBootstrap withUseDnsSec(
boolean useDnsSec);

public abstract HttpProxyServerBootstrap withTransparent(
boolean transparent);

public abstract HttpProxyServerBootstrap withIdleConnectionTimeout(
int idleConnectionTimeout);

/**
* Starts the server.
*
* @param localOnly
* If true, the server will only allow connections from the local
* computer. This can significantly improve security in some
* cases.
* @param anyAddress
* Whether or not to bind to "any" address - 0.0.0.0. This is the
* default.
* @return the newly built and started server
*/
public abstract HttpProxyServer start(boolean localOnly,
boolean anyAddress);

/**
* Builds and starts the server.
*
* @return the newly built and started server
*/
public abstract HttpProxyServer start();

}
3 changes: 1 addition & 2 deletions src/main/java/org/littleshoot/proxy/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.PropertyConfigurator;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer.DefaultHttpProxyServerBootstrap;
import org.littleshoot.proxy.impl.ProxyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -79,7 +78,7 @@ public static void main(final String... args) {
}

System.out.println("About to start server on port: " + port);
DefaultHttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
.bootstrapFromFile("./littleproxy.properties")
.withPort(port);

Expand Down
Loading

0 comments on commit 79235be

Please sign in to comment.