-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added server connector builder (#93)
* Added ServerConnectorBuilder and refactored HttpsConnectorFactory * Refactored HttpConnectorFactory * Corrected build command * Added parameter for Server * Corrected http listener address * Removed not necessary files * Corrected import command * Changed variable context * Update src/main/java/winstone/ServerConnectorBuilder.java Co-Authored-By: Jesse Glick <jglick@cloudbees.com> * Update src/main/java/winstone/ServerConnectorBuilder.java Co-Authored-By: Jesse Glick <jglick@cloudbees.com> * Added keep alive timeout and fixed linting * Update HttpsConnectorFactory.java * Update .gitignore Co-authored-by: Jesse Glick <jglick@cloudbees.com>
- Loading branch information
Showing
6 changed files
with
111 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ target | |
.project | ||
.settings | ||
dependency-reduced-pom.xml | ||
.idea/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package winstone; | ||
|
||
import org.eclipse.jetty.server.ForwardedRequestCustomizer; | ||
import org.eclipse.jetty.server.HttpConfiguration; | ||
import org.eclipse.jetty.server.HttpConnectionFactory; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
|
||
class ServerConnectorBuilder { | ||
|
||
private int listenerPort; | ||
private int keepAliveTimeout; | ||
private int acceptors; | ||
private int selectors; | ||
private int requestHeaderSize; | ||
private String listenerAddress; | ||
private Server server; | ||
private SslContextFactory sslContextFactory; | ||
|
||
public ServerConnectorBuilder withListenerPort(int listenerPort) { | ||
this.listenerPort = listenerPort; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withKeepAliveTimeout(int keepAliveTimeout) { | ||
this.keepAliveTimeout = keepAliveTimeout; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withListenerAddress(String listenerAddress) { | ||
this.listenerAddress = listenerAddress; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withServer(Server server) { | ||
this.server = server; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withAcceptors(int acceptors) { | ||
this.acceptors = acceptors; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withSelectors(int selectors) { | ||
this.selectors = selectors; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withSslContext(SslContextFactory sslContextFactory) { | ||
this.sslContextFactory = sslContextFactory; | ||
return this; | ||
} | ||
|
||
public ServerConnectorBuilder withRequestHeaderSize(int requestHeaderSize) { | ||
this.requestHeaderSize = requestHeaderSize; | ||
return this; | ||
} | ||
|
||
public ServerConnector build() { | ||
|
||
ServerConnector sc; | ||
|
||
if (sslContextFactory != null) { | ||
sc = new ServerConnector(server, acceptors, selectors, sslContextFactory); | ||
} else { | ||
sc = new ServerConnector(server, acceptors, selectors); | ||
} | ||
|
||
sc.setPort(listenerPort); | ||
sc.setHost(listenerAddress); | ||
sc.setIdleTimeout(keepAliveTimeout); | ||
|
||
HttpConfiguration hc = sc.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration(); | ||
hc.addCustomizer(new ForwardedRequestCustomizer()); | ||
hc.setRequestHeaderSize(requestHeaderSize); | ||
|
||
return sc; | ||
|
||
} | ||
|
||
} |
1 comment
on commit 5e1a898
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpConfiguration hc = sc.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
hc.addCustomizer(new ForwardedRequestCustomizer());
hc.setRequestHeaderSize(requestHeaderSize);
cause of https://issues.jenkins-ci.org/browse/JENKINS-61823