Dart Documentationangular.mockMockHttpRequest

MockHttpRequest class

Mock implementation of the HttpRequest object returned from the HttpBackend.

class MockHttpRequest implements HttpRequest {
 final bool supportsCrossOrigin = false;
 final bool supportsLoadEndEvent = false;
 final bool supportsOverrideMimeType = false;
 final bool supportsProgressEvent = false;
 final Events on = null;

 final Stream<ProgressEvent> onAbort = null;
 final Stream<ProgressEvent> onError = null;
 final Stream<ProgressEvent> onLoad = null;
 final Stream<ProgressEvent> onLoadEnd = null;
 final Stream<ProgressEvent> onLoadStart = null;
 final Stream<ProgressEvent> onProgress = null;
 final Stream<ProgressEvent> onReadyStateChange = null;

 final Stream<ProgressEvent> onTimeout = null;
 final int readyState = 0;

 get responseText => response == null ? null : "$response";
 final responseXml = null;
 final String statusText = null;
 final HttpRequestUpload upload = null;

 String responseType = null;
 int timeout = 0;
 bool withCredentials;

 final int status;
 final response;
 final String headers;

 MockHttpRequest(int this.status, String this.response, [this.headers]);

 void abort() {}
 bool dispatchEvent(Event event) => false;
 String getAllResponseHeaders() {
   if (headers == null) return null;
   return headers;
 }
 String getResponseHeader(String header) => null;

 void open(String method, String url, {bool async, String user, String password}) {}
 void overrideMimeType(String override) {}
 void send([data]) {}
 void setRequestHeader(String header, String value) {}
 void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) {}
 void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) {}
}

Implements

HttpRequest

Constructors

new MockHttpRequest(int status, String response, [String headers]) #

General constructor for any type of request (GET, POST, etc).

This call is used in conjunction with open:

var request = new HttpRequest();
request.open('GET', 'http://dartlang.org');
request.onLoad.listen((event) => print(
    'Request complete ${event.target.reponseText}'));
request.send();

is the (more verbose) equivalent of

HttpRequest.getString('http://dartlang.org').then(
    (result) => print('Request complete: $result'));
docs inherited from HttpRequest
MockHttpRequest(int this.status, String this.response, [this.headers]);

Properties

final int hashCode #

inherited from Interceptor

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

docs inherited from Object
int get hashCode => Primitives.objectHashCode(this);

final String headers #

final String headers

final Events on #

This is an ease-of-use accessor for event streams which should only be used when an explicit accessor is not available.

docs inherited from EventTarget
final Events on = null

final Stream<ProgressEvent> onAbort #

final Stream<ProgressEvent> onAbort = null

final Stream<ProgressEvent> onError #

final Stream<ProgressEvent> onError = null

final Stream<ProgressEvent> onLoad #

final Stream<ProgressEvent> onLoad = null

final Stream<ProgressEvent> onLoadEnd #

final Stream<ProgressEvent> onLoadEnd = null

final Stream<ProgressEvent> onLoadStart #

final Stream<ProgressEvent> onLoadStart = null

final Stream<ProgressEvent> onProgress #

final Stream<ProgressEvent> onProgress = null

final Stream<ProgressEvent> onReadyStateChange #

Event listeners to be notified every time the HttpRequest object's readyState changes values.

docs inherited from HttpRequest
final Stream<ProgressEvent> onReadyStateChange = null

final Stream<ProgressEvent> onTimeout #

final Stream<ProgressEvent> onTimeout = null

final int readyState #

Indicator of the current state of the request:

Value State Meaning
0 unsent open() has not yet been called
1 opened send() has not yet been called
2 headers received sent() has been called; response headers and status are available
3 loading responseText holds some data
4 done request is complete
docs inherited from HttpRequest
final int readyState = 0

final response #

The data received as a reponse from the request.

The data could be in the form of a String, ByteBuffer, Document, Blob, or json (also a String). null indicates request failure.

docs inherited from HttpRequest
final response

final String responseText #

inherited from HttpRequest

The response in string form or `null on failure.

final String responseText

String responseType #

String telling the server the desired response format.

Default is String. Other options are one of 'arraybuffer', 'blob', 'document', 'json', 'text'. Some newer browsers will throw NSERRORDOMINVALIDACCESS_ERR if responseType is set while performing a synchronous request.

See also: MDN responseType

docs inherited from HttpRequest
String responseType = null

final responseXml #

The request response, or null on failure.

The response is processed as text/xml stream, unless responseType = 'document' and the request is synchronous.

docs inherited from HttpRequest
final responseXml = null

final Type runtimeType #

inherited from Interceptor

A representation of the runtime type of the object.

docs inherited from Object
Type get runtimeType => getRuntimeType(this);

final int status #

The http result code from the request (200, 404, etc). See also: Http Status Codes

docs inherited from HttpRequest
final int status

final String statusText #

The request response string (such as \"200 OK\"). See also: Http Status Codes

docs inherited from HttpRequest
final String statusText = null

final bool supportsCrossOrigin #

Checks to see if the current platform supports making cross origin requests.

Note that even if cross origin requests are supported, they still may fail if the destination server does not support CORS requests.

docs inherited from HttpRequest
final bool supportsCrossOrigin = false

final bool supportsLoadEndEvent #

Checks to see if the LoadEnd event is supported on the current platform.

docs inherited from HttpRequest
final bool supportsLoadEndEvent = false

final bool supportsOverrideMimeType #

Checks to see if the overrideMimeType method is supported on the current platform.

docs inherited from HttpRequest
final bool supportsOverrideMimeType = false

final bool supportsProgressEvent #

Checks to see if the Progress event is supported on the current platform.

docs inherited from HttpRequest
final bool supportsProgressEvent = false

int timeout #

int timeout = 0

final HttpRequestUpload upload #

EventTarget that can hold listeners to track the progress of the request. The events fired will be members of HttpRequestUploadEvents.

docs inherited from HttpRequest
final HttpRequestUpload upload = null

bool withCredentials #

True if cross-site requests should use credentials such as cookies or authorization headers; false otherwise.

This value is ignored for same-site requests.

docs inherited from HttpRequest
bool withCredentials

Operators

bool operator ==(other) #

inherited from Interceptor

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw or return null.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so equality of two objects should not change over time, or at least only change if one of the objects was modified.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

docs inherited from Object
bool operator ==(other) => identical(this, other);

Methods

void abort() #

Stop the current request.

The request can only be stopped if readyState is HEADERS_RECIEVED or LOADING. If this method is not in the process of being sent, the method has no effect.

docs inherited from HttpRequest
void abort() {}

bool dispatchEvent(Event event) #

bool dispatchEvent(Event event) => false;

String getAllResponseHeaders() #

Retrieve all the response headers from a request.

null if no headers have been received. For multipart requests, getAllResponseHeaders will return the response headers for the current part of the request.

See also HTTP response headers for a list of common response headers.

docs inherited from HttpRequest
String getAllResponseHeaders() {
 if (headers == null) return null;
 return headers;
}

String getResponseHeader(String header) #

Return the response header named header, or null if not found.

See also HTTP response headers for a list of common response headers.

docs inherited from HttpRequest
String getResponseHeader(String header) => null;

dynamic noSuchMethod(Invocation invocation) #

inherited from Interceptor

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

docs inherited from Object
dynamic noSuchMethod(Invocation invocation) {
 throw new NoSuchMethodError(
     this,
     invocation.memberName,
     invocation.positionalArguments,
     invocation.namedArguments);
}

void open(String method, String url, {bool async, String user, String password}) #

Specify the desired url, and method to use in making the request.

By default the request is done asyncronously, with no user or password authentication information. If async is false, the request will be send synchronously.

Calling open again on a currently active request is equivalent to calling abort.

Note: Most simple HTTP requests can be accomplished using the getString, request, requestCrossOrigin, or postFormData methods. Use of this open method is intended only for more complext HTTP requests where finer-grained control is needed.

docs inherited from HttpRequest
void open(String method, String url, {bool async, String user, String password}) {}

void overrideMimeType(String override) #

Specify a particular MIME type (such as text/xml) desired for the response.

This value must be set before the request has been sent. See also the list of common MIME types

docs inherited from HttpRequest
void overrideMimeType(String override) {}

void send([data]) #

Send the request with any given data.

Note: Most simple HTTP requests can be accomplished using the getString, request, requestCrossOrigin, or postFormData methods. Use of this send method is intended only for more complext HTTP requests where finer-grained control is needed.

See also:

docs inherited from HttpRequest
void send([data]) {}

void setRequestHeader(String header, String value) #

void setRequestHeader(String header, String value) {}

String toString() #

inherited from Interceptor

Returns a string representation of this object.

docs inherited from Object
String toString() => Primitives.objectToString(this);

void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) #

void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) {}

void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #

void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) {}