View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.client;
20  
21  import org.eclipse.jetty.client.api.Request;
22  import org.eclipse.jetty.client.api.Response;
23  
24  /**
25   * <p>A protocol handler performs HTTP protocol operations on
26   * behalf of the application, typically like a browser would.</p>
27   * <p>A typical example is handling HTTP redirects. {@link HttpClient}
28   * could just return the redirect response to the application,
29   * but the application would have to implement the redirect
30   * functionality (while browsers do this automatically).</p>
31   */
32  public interface ProtocolHandler
33  {
34      /**
35       * @return a unique name among protocol handlers
36       */
37      public String getName();
38  
39      /**
40       * <p>Inspects the given {@code request} and {@code response}
41       * to detect whether this protocol handler should handle them.</p>
42       * <p>For example, a redirect protocol handler can inspect the
43       * response code and return true if it is a redirect response code.</p>
44       * <p>This method is being called just after the response line has
45       * been parsed, and before the response headers are available.</p>
46       *
47       * @param request  the request to accept
48       * @param response the response to accept
49       * @return true if this protocol handler can handle the given request and response
50       */
51      public boolean accept(Request request, Response response);
52  
53      /**
54       * @return a response listener that will handle the request and response
55       * on behalf of the application.
56       */
57      public Response.Listener getResponseListener();
58  }