Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy support #281

Closed
sameerhr84 opened this issue May 21, 2019 · 2 comments · Fixed by #364
Closed

Proxy support #281

sameerhr84 opened this issue May 21, 2019 · 2 comments · Fixed by #364
Assignees
Milestone

Comments

@sameerhr84
Copy link

sameerhr84 commented May 21, 2019

Problem or use case

Most of the use cases we have requires proxy support for the MQTT client. Do we have this feature

Preferred solution or suggestions

can MqttChannelInitializer have the ability to inject proxy handler as part of initMqtt(...) methods

adding proxy to pipeline:

private void addProxyHandlerIfNeeded(ChannelPipeline pipeline, HttpProxyConfig httpProxyConfig,
        @Nullable String passwordOverride) throws Exception {
    String proxyHost = httpProxyConfig.host();
    if (proxyHost.isEmpty()) {
        return;
    }
    int proxyPort = MoreObjects.firstNonNull(httpProxyConfig.port(), 80);
    SocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
    String username = httpProxyConfig.username();
    if (username.isEmpty()) {
        pipeline.addLast(new HttpProxyHandler(proxyAddress));
    } else {
        String password = getPassword(httpProxyConfig, passwordOverride);
        pipeline.addLast(new HttpProxyHandler(proxyAddress, username, password));
    }
}

Proxy handler similar to below :

public final ProxyHandler newProxyHandler() {
	InetSocketAddress proxyAddr = this.address.get();
	String username = this.username;
	String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
			this.password.apply(username) : null;

	switch (this.type) {
		case HTTP:
			return Objects.nonNull(username) && Objects.nonNull(password) ?
					new HttpProxyHandler(proxyAddr, username, password) :
					new HttpProxyHandler(proxyAddr);
		case SOCKS4:
			return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
					new Socks4ProxyHandler(proxyAddr);
		case SOCKS5:
			return Objects.nonNull(username) && Objects.nonNull(password) ?
					new Socks5ProxyHandler(proxyAddr, username, password) :
					new Socks5ProxyHandler(proxyAddr);
	}
	throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
}
@SgtSilvio SgtSilvio changed the title Do we have support of proxy Proxy support Oct 2, 2019
@SgtSilvio SgtSilvio added this to the 1.2 milestone Nov 26, 2019
@SgtSilvio SgtSilvio linked a pull request Mar 2, 2020 that will close this issue
@SgtSilvio SgtSilvio self-assigned this Mar 4, 2020
@SgtSilvio
Copy link
Member

@sameerhr84 proxy support is now part of version 1.2.0

@sameerhr84
Copy link
Author

Thank you @SgtSilvio for helping with this feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants