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

http response without content #5

Closed
tanimasaini opened this issue Apr 14, 2015 · 1 comment
Closed

http response without content #5

tanimasaini opened this issue Apr 14, 2015 · 1 comment

Comments

@tanimasaini
Copy link

Hi,

I am using this client to make http requests. There are cases in which I am only interested in headers and not in content of the response. I dont want to use "head" method as not all servers support this methis. I want to use "get" method but once I get the headers I dont want to receive content from the server. Is it possible with this library or any pointers how it can be done using netty.

Thanks & Regards,
Tanima

@timboudreau
Copy link
Owner

You'll want something like this. It's slightly awkard because you need a reference to the ResponseFuture inside the receiver (maybe there should a way for the receiver to call an instance method to cancel), but you would do it like this:

        final AtomicReference<ResponseFuture> futureRef = new AtomicReference<>();

        futureRef.set(client.get().setURL("http://foo.example").on(StateType.HeadersReceived, new Receiver<HttpHeaders>() {

            @Override
            public void receive(HttpHeaders object) {
                // do something with the headers
                futureRef.get().cancel();
            }

        }).execute());

You may want to override the Receiver's onFail() and onFail(Exception) methods to be notified if a connection cannot be opened or is unexpectedly closed by the server.

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