package com.intuit.karate;

import com.intuit.karate.netty.NettyUtils;
import com.intuit.karate.netty.ProxyResponse;
import com.intuit.karate.netty.ProxyServer;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
import java.io.File;
import org.junit.Test;
import org.slf4j.LoggerFactory;

/**
 *
 * @author pthomas3
 */
public class ProxyServerSslMain {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ProxyServerSslMain.class);

    private String html = FileUtils.toString(new File("src/test/java/com/intuit/karate/temp.html"));

    @Test
    public void testProxy() {
        ProxyServer server = new ProxyServer(8090,
                req -> {
                    if ("httpbin.org".equals(req.context.host)) {
                        FullHttpResponse response = NettyUtils.createResponse(HttpResponseStatus.OK, html);
                        response.headers().add(HttpHeaderNames.CONTENT_TYPE, "text/html");
                        return new ProxyResponse(req.context, req.request, response);
                    }
                    return null;
                },
                res -> {
                    if ("corte.si".equals(res.context.host) && res.isHtml()) {
                        logger.debug("returning html: {}", html);
                        return NettyUtils.transform(res.response, html);
                    }
                    return null;
                });
        server.waitSync();
    }

}

@@ -154,16 +154,18 @@
 Server;%0A
+//
 import i
@@ -205,24 +205,26 @@
 tpResponse;%0A
+//
 import io.ne
@@ -263,16 +263,18 @@
 rNames;%0A
+//
 import i
@@ -780,24 +780,26 @@
    req -%3E %7B%0A
+//
             
@@ -848,24 +848,26 @@
 xt.host)) %7B%0A
+//
             
@@ -954,32 +954,34 @@
 atus.OK, html);%0A
+//
                 
@@ -1055,16 +1055,18 @@
 html%22);%0A
+//
         
@@ -1143,16 +1143,18 @@
 ponse);%0A
+//
         

fix build - realized that maven shade has implications we cant use netty core classes in the public api or tests