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

how to send request like squid to SquidEchoHandler? #8

Open
bruceMichael opened this issue May 29, 2013 · 1 comment
Open

how to send request like squid to SquidEchoHandler? #8

bruceMichael opened this issue May 29, 2013 · 1 comment

Comments

@bruceMichael
Copy link

i try to simulate a request in java api to integrate with SquidEchoHandler, but failed. perhaps some header or other param is wrong.
could any body give a example,thanks!

@erdbeerschnitzel
Copy link

Here is an example:

        String host = "hostname";
        int CHUNK_SIZE = 1024*1024;

        ClientBootstrap bootstrap = new ClientBootstrap(new OioClientSocketChannelFactory(Executors.newCachedThreadPool()));

        bootstrap.setPipelineFactory(new IcapClientChannelPipeline());
        ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, 1344));

        Channel channel = future.awaitUninterruptibly().getChannel();

        if (!future.isSuccess()) {
            future.getCause().printStackTrace();
            bootstrap.releaseExternalResources();
            return;
        }

        IcapRequest request = new DefaultIcapRequest(IcapVersion.ICAP_1_0, IcapMethod.RESPMOD, "icap://" + host + ":1344/", host + ":1344");

        HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/test");

        httpRequest.setHeader(HttpHeaders.Names.HOST, host + ":1344");
        httpRequest.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);

        HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

        httpResponse.setHeader(HttpHeaders.Names.HOST, host + ":1344");
        httpResponse.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
        httpResponse.setHeader(HttpHeaders.Names.CACHE_CONTROL, HttpHeaders.Values.NO_CACHE);
        httpResponse.setContent(ChannelBuffers.wrappedBuffer(Files.readAllBytes(Paths.get("/home/bla/File.zip"))));

        request.setHttpRequest(httpRequest);
        request.setHttpResponse(httpResponse);
        request.setHeader(HttpHeaders.Names.ALLOW, 204);

        channel.write(request);

        channel.getCloseFuture().awaitUninterruptibly();
        bootstrap.releaseExternalResources();

eblocker pushed a commit to eblocker/netty-icap that referenced this issue Jan 15, 2020
…-netty-icap-support-parsing-responses-with-use-original-body to develop

* commit '84531adb076eb958df3ee96d700b934e7d276fa3':
  [EB1-2050] set use-original-body on aggregated messages
  [EB1-2050] added test for decoding use-original-body extension
  [EB1-2050] fixed typos
  [EB1-2050] parse all chunk extensions
  [EB1-2049] add trailer for zero size previews
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants