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;
8 * HTTP request (GET, PUT or POST).
9 * Note: All methods must be called on the Executor passed in during creation.
11 public interface UrlRequest {
13 * More setters go here. They may only be called before start (Maybe
14 * also allow during redirects). Could optionally instead use arguments
15 * to URLRequestFactory when creating the request.
19 * Sets the HTTP method verb to use for this request.
21 * <p>The default when this method is not called is "GET" if the request has
22 * no body or "POST" if it does.
24 * @param method "GET", "HEAD", "DELETE", "POST" or "PUT".
26 public void setHttpMethod(String method);
29 * Adds a request header. Must be done before request has started.
31 * @param header Header name
32 * @param value Header value
34 public void addHeader(String header, String value);
37 * Starts the request, all callbacks go to listener.
40 public void start(UrlRequestListener listener);
43 * Can be called at any time.
49 * @return True if the request has been cancelled by the embedder.
50 * TBD(mmenke): False in all other cases (Including errors).
52 public boolean isCanceled();
55 * Can be called at any time, but the request may continue behind the
56 * scenes, depending on when it's called. None of the listener's methods
57 * will be called while paused, until and unless the request is resumed.
58 * (Note: This allows us to have more than one ByteBuffer in flight,
59 * if we want, as well as allow pausing at any point).
61 * TBD: May need different pause behavior.
66 * Returns True if paused. False if not paused or is cancelled.
69 public boolean isPaused();
72 * When resuming, any pending callback to the listener will be called
78 * Note: There are deliberately no accessors for the results of the request
79 * here. Having none removes any ambiguity over when they are populated,
80 * particularly in the redirect case.