53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
package cx.lehmann.gemini.gemini;
|
|
|
|
import io.vertx.core.AbstractVerticle;
|
|
import io.vertx.core.Promise;
|
|
import io.vertx.core.net.NetServerOptions;
|
|
import io.vertx.core.net.PemKeyCertOptions;
|
|
|
|
public class MainVerticle extends AbstractVerticle {
|
|
|
|
@Override
|
|
public void start(Promise<Void> startPromise) throws Exception {
|
|
NetServerOptions options=new NetServerOptions();
|
|
|
|
String certPath="c:/temp/cert.pem";
|
|
|
|
options.setPemKeyCertOptions(new PemKeyCertOptions()
|
|
.setCertPath(certPath)
|
|
.setKeyPath(certPath))
|
|
.setSsl(true);
|
|
// .setClientAuth(ClientAuth.REQUEST);
|
|
|
|
vertx.createNetServer(options).connectHandler(conn -> {
|
|
conn.handler(event -> {
|
|
String url=event.toString("UTF-8");
|
|
if(!url.endsWith("\r\n")) {
|
|
conn.write("40 format error\r\n");
|
|
conn.close();
|
|
} else {
|
|
url=url.substring(0, url.length()-2);
|
|
conn.write("20 text/gemini\r\n");
|
|
conn.write(url);
|
|
conn.write("\n");
|
|
// try {
|
|
// conn.write(conn.peerCertificates().toString());
|
|
// } catch (SSLPeerUnverifiedException ex) {
|
|
// // TODO Auto-generated catch block
|
|
// ex.printStackTrace();
|
|
// }
|
|
conn.close();
|
|
}
|
|
}
|
|
);
|
|
}).listen(1965, server -> {
|
|
if (server.succeeded()) {
|
|
startPromise.complete();
|
|
System.out.println("Gemini server started on port 1965");
|
|
} else {
|
|
startPromise.fail(server.cause());
|
|
}
|
|
});
|
|
}
|
|
}
|