1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.net;
7 import java.nio.ByteBuffer;
10 * Note: All methods will be called on the thread of the Executor used during
11 * construction of the UrlRequest.
13 public interface UrlRequestListener {
15 * Called before following redirects. The redirect will automatically be
16 * followed, unless the request is paused or cancelled during this
17 * callback. If the redirect response has a body, it will be ignored.
18 * This will only be called between start and onResponseStarted.
20 * @param request Request being redirected.
21 * @param info Response information.
22 * @param newLocationUrl Location where request is redirected.
24 public void onRedirect(UrlRequest request,
26 String newLocationUrl);
29 * Called when the final set of headers, after all redirects,
30 * is received. Can only be called once for each request.
32 * @param request Request that started to get response.
33 * @param info Response information.
35 public void onResponseStarted(UrlRequest request, ResponseInfo info);
38 * Called whenever data is received. The ByteBuffer remains
39 * valid only for the duration of the callback. Or if the callback
40 * pauses the request, it remains valid until the request is resumed.
41 * Cancelling the request also invalidates the buffer.
43 * @param request Request that received data.
44 * @param info Response information.
45 * @param byteBuffer Received data.
47 public void onDataReceived(UrlRequest request,
49 ByteBuffer byteBuffer);
52 * Called when request is completed successfully, no callbacks will be
55 * @param request Request that succeeded.
56 * @param info Response information.
58 public void onSucceeded(UrlRequest request, ExtendedResponseInfo info);
61 * Called if request failed for any reason after start(). Once
62 * called, no other functions can be called. UrlRequestException
63 * provides information about error.
65 * @param request Request that failed.
66 * @param info Response information.
67 * @param error information about error.
69 public void onFailed(UrlRequest request,
71 UrlRequestException error);