File, socket, HTTP, and other I/O support for server applications.
The IO library is used for Dart server applications, which run on a stand-alone Dart VM from the command line. This library does not work in browser based applications.
This library allows you to work with files, directories, sockets, processes, HTTP servers and clients, and more.
An instance of the default implementation of the GZipCodec.
An instance of the default implementation of the ZLibCodec.
Global exit code for the Dart VM.
The exit code is global for the Dart VM and the last assignment to exitCode from any isolate determines the exit code of the Dart VM on normal termination.
Returns the PID of the current process.
Exit the Dart VM process immediately with the given status code.
This does not wait for any asynchronous operations to terminate. Using exit is therefore very likely to lose data.
Sleep for the duration specified in duration.
Use this with care, as no asynchronous operations can be processed in a isolate while it is blocked in a sleep call.
Builds a list of bytes, allowing bytes and lists of bytes to be added at the end.
Used to efficiently collect bytes and lists of bytes, using an internal buffer. Note that it's optimized for IO, using an initial buffer of 1K bytes.
Returns true if the buffer is empty.
Returns true if the buffer is empty.
The number of bytes in the builder.
Construct a new empty BytesBuilder.
Appends bytes to the current contents of the builder.
Each value of bytes will be bit-representation truncated to the range 0 .. 255.
Append byte to the current contents of the builder.
The byte will be bit-representation truncated to the range 0 .. 255.
Clear the contents of the builder.
Returns the contents of this and clears this.
The list returned is a view of the the internal buffer, limited to the length.
Returns a copy of the current contents of the builder.
Leaves the contents of the builder intact.
An exception that happens in the handshake phase of establishing a secure network connection, when looking up or verifying a certificate.
Representation of a content type. An instance of ContentType is immutable.
Gets the character set.
Gets the mime-type, without any parameters.
Gets the primary type.
Gets the sub type.
Creates a new content type object setting the primary type and sub type. The charset and additional parameters can also be set using charset and parameters. If charset is passed and parameters contains charset as well the passed charset will override the value in parameters. Keys and values passed in parameters will be converted to lower case.
Creates a new content type object from parsing a Content-Type header value. As primary type, sub type and parameter names and values are not case sensitive all these values will be converted to lower case. Parsing this string
text/html; charset=utf-8will create a content type object with primary type
text, sub type html and parameter charset with value utf-8.
Representation of a cookie. For cookies received by the server as Cookie header values only name and value fields will be set. When building a cookie for the 'set-cookie' header in the server and when receiving cookies in the client as 'set-cookie' headers all fields can be used.
Gets and sets the domain.
Gets and sets the expiry date.
Gets and sets whether this cookie is HTTP only.
Gets and sets the max age. A value of 0 means delete cookie now.
Gets and sets the name.
Gets and sets the path.
Gets and sets whether this cookie is secure.
Gets and sets the value.
Creates a new cookie optionally setting the name and value.
Creates a new cookie by parsing a header value from a 'set-cookie' header.
Returns the formatted string representation of the cookie. The string representation can be used for for setting the Cookie or 'set-cookie' headers
When detaching a socket from either the HttpServer or the HttpClient due to a HTTP connection upgrade there might be unparsed data already read from the socket. This unparsed data together with the detached socket is returned in an instance of this class.
A reference to a directory (or _folder_) on the file system.
Gets the path of this directory.
Returns a Directory instance whose path is the absolute path to this.
The absolute path is computed by prefixing a relative path with the current working directory, and returning an absolute path unchanged.
Creates a directory object pointing to the current working directory.
Sets the current working directory of the Dart process including all running isolates. The new value set can be either a Directory or a String.
The new value is passed to the OS's system call unchanged, so a relative path passed as the new working directory will be resolved by the OS.
Note that setting the current working directory is a synchronous operation and that it changes the the working directory of all isolates.
Use this with care - especially when working with asynchronous operations and multiple isolates. Changing the working directory, while asynchronous operations are pending or when other isolates are working with the file system, can lead to unexpected results.
Creates a directory object. The path is either an absolute path, or it is a relative path which is interpreted relative to the directory in which the Dart VM was started.
Creates the directory with this name.
If recursive is false, only the last directory in the path is created. If recursive is true, all non-existing path components are created. If the directory already exists nothing is done.
Returns a Future<Directory> that completes with this directory once it has been created. If the directory cannot be created the future completes with an exception.
Synchronously creates the directory with this name.
If recursive is false, only the last directory in the path is created. If recursive is true, all non-existing path components are created. If the directory already exists nothing is done.
If the directory cannot be created an exception is thrown.
Creates a temporary directory with a name based on the current path. The path is used as a template, and additional characters are appended to it to make a unique temporary directory name. If the path is the empty string, a default system temp directory and name are used for the template.
Returns a Future<Directory> that completes with the newly created temporary directory.
Synchronously creates a temporary directory with a name based on the current path. The path is used as a template, and additional characters are appended to it to make a unique temporary directory name. If the path is the empty string, a default system temp directory and name are used for the template. Returns the newly created temporary directory.
Lists the sub-directories and files of this Directory. Optionally recurses into sub-directories.
If followLinks is false, then any symbolic links found are reported as Link objects, rather than as directories or files, and are not recursed into.
If followLinks is true, then working links are reported as directories or files, depending on their type, and links to directories are recursed into. Broken links are reported as Link objects. If a symbolic link makes a loop in the file system, then a recursive listing will not follow a link twice in the same recursive descent, but will report it as a Link the second time it is seen.
The result is a stream of FileSystemEntity objects for the directories, files, and links.
Lists the sub-directories and files of this Directory. Optionally recurses into sub-directories.
If followLinks is false, then any symbolic links found are reported as Link objects, rather than as directories or files, and are not recursed into.
If followLinks is true, then working links are reported as directories or files, depending on their type, and links to directories are recursed into. Broken links are reported as Link objects. If a link makes a loop in the file system, then a recursive listing will not follow a link twice in the same recursive descent, but will report it as a Link the second time it is seen.
Returns a List containing FileSystemEntity objects for the directories, files, and links.
Renames this directory. Returns a Future<Directory> that completes with a Directory instance for the renamed directory.
If newPath identifies an existing directory, that directory is replaced. If newPath identifies an existing file, the operation fails and the future completes with an exception.
Synchronously renames this directory. Returns a Directory instance for the renamed directory.
If newPath identifies an existing directory, that directory is replaced. If newPath identifies an existing file the operation fails and an exception is thrown.
Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all '..' and '.' path segments. resolveSymbolicLinks returns a Future<String>
resolveSymbolicLinks uses the operating system's native filesystem api to resolve the path, using the realpath function on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinks completes the returned Future with an FileException.
On Windows, symbolic links are resolved to their target before applying a '..' that follows, and on other platforms, the '..' is applied to the symbolic link without resolving it. The second behavior can be emulated on Windows by processing any '..' segments before calling resolveSymbolicLinks. One way of doing this is with the URI class: :new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();, since resolve removes '..' segments.
Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all '..' and '.' path segments.
resolveSymbolicLinksSync uses the operating system's native filesystem api to resolve the path, using the realpath function on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinksSync throws a FileException.
On Windows, symbolic links are resolved to their target before applying a '..' that follows, and on other platforms, the '..' is applied to the symbolic link without resolving it. The second behavior can be emulated on Windows by processing any '..' segments before calling resolveSymbolicLinks. One way of doing this is with the URI class: :new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();, since resolve removes '..' segments.
Returns a human readable string for this Directory instance.
Returns a string representation of this object.
A reference to a file on the file system.
If path is a symbolic link, rather than a file, then the methods of File operate on the ultimate target of the link, except for File.delete and File.deleteSync, which operate on the link.
To operate on the underlying file data there are two options:
StreamIOSink this.openWrite()(). Returns a File instance whose path is the absolute path to this.
The absolute path is computed by prefixing a relative path with the current working directory, and returning an absolute path unchanged.
Get a Directory object for the directory containing this file.
Get the path of the file.
Create a File object.
Create the file. Returns a Future<File> that completes with the file when it has been created.
Existing files are left untouched by create. Calling create on an existing file might fail if there are restrictive permissions on the file.
Synchronously create the file. Existing files are left untouched by createSync. Calling createSync on an existing file might fail if there are restrictive permissions on the file.
Throws a FileException if the operation fails.
Get the canonical full path corresponding to the file path. Returns a Future<String> that completes with the path.
*FullPath is deprecated. Use absolutePath or resolveSymbolicLinks instead. FullPath will be removed the 23rd of September, 2013.*
Synchronously get the canonical full path corresponding to the file path.
Throws a FileException if the operation fails.
*FullPathSync is deprecated. Use absolutePathSync or resolveSymbolicLinksSync instead. FullPathSync will be removed the 23rd of September, 2013.*
Get the last-modified time of the file. Returns a Future<DateTime> that completes with a DateTime object for the modification date.
Get the last-modified time of the file. Throws an exception if the file does not exist.
Throws a FileException if the operation fails.
Get the length of the file. Returns a Future<int> that completes with the length in bytes.
Synchronously get the length of the file.
Throws a FileException if the operation fails.
Open the file for random access operations. Returns a Future<RandomAccessFile> that completes with the opened random access file. RandomAccessFiles must be closed using the RandomAccessFile.close method.
Files can be opened in three modes:
FileMode.READ: open the file for reading.
FileMode.WRITE: open the file for both reading and writing and truncate the file to length zero. If the file does not exist the file is created.
FileMode.APPEND: same as FileMode.WRITE except that the file is not truncated.
Create a new independent Stream for the contents of this file.
If start is present, the file will be read from byte-offset start. Otherwise from the beginning (index 0).
If end is present, only up to byte-index end will be read. Otherwise, until end of file.
In order to make sure that system resources are freed, the stream must be read to completion or the subscription on the stream must be cancelled.
Synchronously open the file for random access operations. The result is a RandomAccessFile on which random access operations can be performed. Opened RandomAccessFiles must be closed using the RandomAccessFile.close method.
See open for information on the mode argument.
Throws a FileException if the operation fails.
Creates a new independent IOSink for the file. The IOSink must be closed when no longer used, to free system resources.
An IOSink for a file can be opened in two modes:
FileMode.WRITE: truncates the file to length zero.FileMode.APPEND: sets the initial write position to the endWhen writing strings through the returned IOSink the encoding specified using encoding will be used. The returned IOSink has an encoding property which can be changed after the IOSink has been created.
Read the entire file contents as a list of bytes. Returns a Future<List<int>> that completes with the list of bytes that is the contents of the file.
Synchronously read the entire file contents as a list of bytes.
Throws a FileException if the operation fails.
Read the entire file contents as lines of text using the given Encoding.
Returns a Future<List<String>> that completes with the lines once the file contents has been read.
Synchronously read the entire file contents as lines of text using the given Encoding.
Throws a FileException if the operation fails.
Read the entire file contents as a string using the given Encoding.
Returns a Future<String> that completes with the string once the file contents has been read.
Synchronously read the entire file contents as a string using the given Encoding.
Throws a FileException if the operation fails.
Renames this file. Returns a Future<File> that completes with a File instance for the renamed file.
If newPath identifies an existing file, that file is replaced. If newPath identifies an existing directory, the operation fails and the future completes with an exception.
Synchronously renames this file. Returns a File instance for the renamed file.
If newPath identifies an existing file, that file is replaced. If newPath identifies an existing directory the operation fails and an exception is thrown.
Write a list of bytes to a file.
Opens the file, writes the list of bytes to it, and closes the file. Returns a Future<File> that completes with this File object once the entire operation has completed.
By default writeAsBytes creates the file for writing and truncates the file if it already exists. In order to append the bytes to an existing file, pass FileMode.APPEND as the optional mode parameter.
Synchronously write a list of bytes to a file.
Opens the file, writes the list of bytes to it and closes the file.
By default writeAsBytesSync creates the file for writing and truncates the file if it already exists. In order to append the bytes to an existing file, pass FileMode.APPEND as the optional mode parameter.
Throws a FileException if the operation fails.
Write a string to a file.
Opens the file, writes the string in the given encoding, and closes the file. Returns a Future<File> that completes with this File object once the entire operation has completed.
By default writeAsString creates the file for writing and truncates the file if it already exists. In order to append the bytes to an existing file, pass FileMode.APPEND as the optional mode parameter.
Synchronously write a string to a file.
Opens the file, writes the string in the given encoding, and closes the file.
By default writeAsStringSync creates the file for writing and truncates the file if it already exists. In order to append the bytes to an existing file, pass FileMode.APPEND as the optional mode parameter.
Throws a FileException if the operation fails.
Returns a string representation of this object.
FileMode describes the modes in which a file can be opened.
A FileStat object represents the result of calling the POSIX stat() function on a file system object. It is an immutable object, representing the snapshotted values returned by the stat() call.
The time of the last access to the data of the file system object. On Windows platforms, this may have 1 day granularity, and be out of date by an hour.
The time of the last change to the data or metadata of the file system object. On Windows platforms, this is instead the file creation time.
The mode of the file system object. Permissions are encoded in the lower 16 bits of this number, and can be decoded using the modeString getter.
The time of the last change to the data of the file system object.
The size of the file system object.
The type of the object (file, directory, or link). If the call to stat() fails, the type of the returned object is NOT_FOUND.
Returns the mode value as a human-readable string, in the format "rwxrwxrwx", reflecting the user, group, and world permissions to read, write, and execute the file system object, with "-" replacing the letter for missing permissions. Extra permission bits may be represented by prepending "(suid)", "(guid)", and/or "(sticky)" to the mode string.
Asynchronously calls the operating system's stat() function on path. Returns a Future which completes with a FileStat object containing the data returned by stat(). If the call fails, completes the future with a FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
Calls the operating system's stat() function on path. Returns a FileStat object containing the data returned by stat(). If the call fails, returns a FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
Returns a string representation of this object.
File system event for newly created file system objects.
Returns a string representation of this object.
File system event for deletion of file system objects.
Returns a string representation of this object.
A FileSystemEntity is a common super class for File and Directory objects.
FileSystemEntity objects are returned from directory listing operations. To determine if a FileSystemEntity is a File or a Directory, perform a type check:
if (entity is File) (entity as File).readAsStringSync();
Returns a FileSystemEntity whose path is the absolute path to this. The type of the returned instance is the type of this.
The absolute path is computed by prefixing a relative path with the current working directory, and returning an absolute path unchanged.
Returns a bool indicating whether this object's path is absolute.
On Windows, a path is absolute if it starts with \\ or a drive letter between a and z (upper or lower case) followed by :\ or :/. On non-Windows, a path is absolute if it starts with /.
Test if watch is supported on the current system.
Mac OS 10.6 and below is not supported.
Deletes this FileSystemEntity.
If the FileSystemEntity is a directory, and if recursive is false, the directory must be empty. Otherwise, if recursive is true, the directory and all sub-directories and files in the directories are deleted. Links are not followed when deleting recursively. Only the link is deleted, not its target.
If recursive is true, the FileSystemEntity is deleted even if the type of the FileSystemEntity doesn't match the content of the file system. This behavior allows delete to be used to unconditionally delete any file system object.
Returns a Future<FileSystemEntity> that completes with this FileSystemEntity when the deletion is done. If the FileSystemEntity cannot be deleted, the future completes with an exception.
Synchronously deletes this FileSystemEntity.
If the FileSystemEntity is a directory, and if recursive is false, the directory must be empty. Otherwise, if recursive is true, the directory and all sub-directories and files in the directories are deleted. Links are not followed when deleting recursively. Only the link is deleted, not its target.
If recursive is true, the FileSystemEntity is deleted even if the type of the FileSystemEntity doesn't match the content of the file system. This behavior allows deleteSync to be used to unconditionally delete any file system object.
Throws an exception if the FileSystemEntity cannot be deleted.
Checks whether the file system entity with this path exists. Returns a Future<bool> that completes with the result.
Since FileSystemEntity is abstract, every FileSystemEntity object is actually an instance of one of the subclasses File, Directory, and Link. Calling exists on an instance of one of these subclasses checks whether the object exists in the file system object exists and is of the correct type (file, directory, or link). To check whether a path points to an object on the file system, regardless of the object's type, use the type static method.
Synchronously checks whether the file system entity with this path exists.
Since FileSystemEntity is abstract, every FileSystemEntity object is actually an instance of one of the subclasses File, Directory, and Link. Calling existsSync on an instance of one of these subclasses checks whether the object exists in the file system object exists and is of the correct type (file, directory, or link). To check whether a path points to an object on the file system, regardless of the object's type, use the typeSync static method.
Checks whether two paths refer to the same object in the file system. Returns a Future<bool> that completes with the result.
Comparing a link to its target returns false, as does comparing two links that point to the same target. To check the target of a link, use Link.target explicitly to fetch it. Directory links appearing inside a path are followed, though, to find the file system object.
Completes the returned Future with an error if one of the paths points to an object that does not exist.
Synchronously checks whether two paths refer to the same object in the file system.
Comparing a link to its target returns false, as does comparing two links that point to the same target. To check the target of a link, use Link.target explicitly to fetch it. Directory links appearing inside a path are followed, though, to find the file system object.
Throws an error if one of the paths points to an object that does not exist.
Checks if type(path) returns FileSystemEntityType.DIRECTORY.
Synchronously checks if typeSync(path) returns FileSystemEntityType.DIRECTORY.
Checks if type(path) returns FileSystemEntityType.FILE.
Synchronously checks if typeSync(path) returns FileSystemEntityType.FILE.
Checks if type(path, followLinks: false) returns FileSystemEntityType.LINK.
Synchronously checks if typeSync(path, followLinks: false) returns FileSystemEntityType.LINK.
Renames this file system entity. Returns a Future<FileSystemEntity> that completes with a FileSystemEntity instance for the renamed file system entity.
If newPath identifies an existing entity of the same type, that entity is replaced. If newPath identifies an existing entity of a different type, the operation fails and the future completes with an exception.
Synchronously renames this file system entity. Returns a FileSystemEntity instance for the renamed entity.
If newPath identifies an existing entity of the same type, that entity is replaced. If newPath identifies an existing entity of a different type, the operation fails and an exception is thrown.
Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all '..' and '.' path segments. resolveSymbolicLinks returns a Future<String>
resolveSymbolicLinks uses the operating system's native filesystem api to resolve the path, using the realpath function on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinks completes the returned Future with an FileException.
On Windows, symbolic links are resolved to their target before applying a '..' that follows, and on other platforms, the '..' is applied to the symbolic link without resolving it. The second behavior can be emulated on Windows by processing any '..' segments before calling resolveSymbolicLinks. One way of doing this is with the URI class: :new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();, since resolve removes '..' segments.
Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all '..' and '.' path segments.
resolveSymbolicLinksSync uses the operating system's native filesystem api to resolve the path, using the realpath function on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinksSync throws a FileException.
On Windows, symbolic links are resolved to their target before applying a '..' that follows, and on other platforms, the '..' is applied to the symbolic link without resolving it. The second behavior can be emulated on Windows by processing any '..' segments before calling resolveSymbolicLinks. One way of doing this is with the URI class: :new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();, since resolve removes '..' segments.
Calls the operating system's stat() function on the path of this FileSystemEntity. Identical to FileStat.stat(this.path).
Returns a Future<FileStat> object containing the data returned by stat().
If the call fails, completes the future with a FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
Synchronously calls the operating system's stat() function on the path of this FileSystemEntity. Identical to FileStat.statSync(this.path).
Returns a FileStat object containing the data returned by stat().
If the call fails, returns a FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
Finds the type of file system object that a path points to. Returns a Future<FileSystemEntityType> that completes with the result.
FileSystemEntityType has the constant instances FILE, DIRECTORY, LINK, and NOT_FOUND. type will return LINK only if the optional named argument followLinks is false, and path points to a link. If the path does not point to a file system object, or any other error occurs in looking up the path, NOT_FOUND is returned. The only error or exception that may be put on the returned future is ArgumentError, caused by passing the wrong type of arguments to the function.
Synchronously finds the type of file system object that a path points to. Returns a FileSystemEntityType.
FileSystemEntityType has the constant instances FILE, DIRECTORY, LINK, and NOT_FOUND. type will return LINK only if the optional named argument followLinks is false, and path points to a link. If the path does not point to a file system object, or any other error occurs in looking up the path, NOT_FOUND is returned. The only error or exception that may be thrown is ArgumentError, caused by passing the wrong type of arguments to the function.
Start watch the FileSystemEntity for changes.
The implementation uses platform-depending event-based APIs for receiving file-system notifixations, thus behvaiour depends on the platform.
Windows: Uses ReadDirectoryChangesW. The implementation supportsonly watching dirctories but supports recursive watching.*
Linux: Uses inotify. The implementation supports watching both files and dirctories, but doesn't support recursive watching.*
Mac OS: Uses FSEvents. The implementation supports watching both files and dirctories, and also recursive watching. Note that FSEvents always use recursion internally, so when disabled, some events are ignored.The system will start listen for events once the returned
Stream is being listened to, not when the call to watch is issued. Note that the returned Stream is endless. To stop the Stream, simply cancel the subscription.
Returns a string representation of this object.
Base event class emitted by FileSystemWatcher.
The path that triggered the event. Depending on the platform and the FileSystemEntity, the path may be relative.
The type of event. See FileSystemEvent for a list of events.
File system event for modifications of file system objects.
If the content was changed and not only the attributes, contentChanged is true.
Returns a string representation of this object.
File system event for moving of file system objects.
If the underlaying implementation is able to identify the destination of the moved file, destination will be set. Otherwise, it will be null.
Returns a string representation of this object.
The GZipCodec encodes raw bytes to GZip compressed bytes and decodes GZip compressed bytes to raw bytes.
The difference between ZLibCodec and GZipCodec is that the GZipCodec wraps the ZLib compressed bytes in GZip frames.
The compression level of the ZLibCodec.
Get a Converter for decoding GZip compressed data.
Get a Converter for encoding to GZip compressed data.
The compression-level can be set in the range of 1..10, with 6 being the default compression level. Levels above 6 will have higher compression rates at the cost of more CPU and memory usage. Levels below 6 will use less CPU and memory, but at the cost of lower compression rates.
An exception that happens in the handshake phase of establishing a secure network connection.
Representation of a header value in the form:
value; parameter1=value1; parameter2=value2
HeaderValue can be used to conveniently build and parse header values on this form.
To build an accepts header with the value
text/plain; q=0.3, text/htmluse code like this:
HttpClientRequest request = ...;
var v = new HeaderValue("text/plain", {"q": "0.3"});
request.headers.add(HttpHeaders.ACCEPT, v);
request.headers.add(HttpHeaders.ACCEPT, "text/html");
To parse the header values use the parse static method.
HttpRequest request = ...;
List<String> values = request.headers[HttpHeaders.ACCEPT];
values.forEach((value) {
HeaderValue v = HeaderValue.parse(value);
// Use v.value and v.parameters
});
An instance of HeaderValue is immutable.
Gets the map of parameters.
This map cannot be modified. invoking any operation which would modify the map will throw UnsupportedError.
Gets the header value.
Creates a new header value object setting the value and parameters.
Creates a new header value object from parsing a header value string with both value and optional parameters.
Returns the formatted string representation in the form:
value; parameter1=value1; parameter2=value2
A client that receives content, such as web pages, from a server using the HTTP protocol.
HttpClient contains a number of methods to send a HTTP request to a HTTP server and receive a HTTP response back.
This is a two-step process, triggered by two futures. When the first future completes with a HttpClientRequest the underlying network connection has been established, but no data has yet been sent. The HTTP headers and body can be set on the request, and close is called to sent it to the server.
The second future, which is returned by close, completes with an HttpClientResponse object when the response is received from the server. This object contains the headers and body of the response.
The future for HttpClientRequest is created by methods such as getUrl() and open().
When the HTTP response is ready a HttpClientResponse object is provided which provides access to the headers and body of the response. The body is available as a stream implemented by HttpClientResponse. If a body is present, it must be read. Otherwise, it'll lead to a resource leaks. Consider using HttpClientResponse.drain if the body is unused.
HttpClient client = new HttpClient();
client.getUrl(Uri.parse("http://www.example.com/"))
.then((HttpClientRequest request) {
// Prepare the request then call close on it to send it.
return request.close();
})
.then((HttpClientResponse response) {
// Process the response.
});
All HttpClient requests set the following header by default:
Accept-Encoding: gzipThis allows the HTTP server to use gzip compression for the body if possible. If this behavior is not desired set the "Accept-Encoding" header to something else.
The HttpClient supports persistent connections and caches network connections to reuse then for multiple requests whenever possible. This means that network connections can be kept open for some time after a request have completed. Use HttpClient.close to force shut down the HttpClient object and close the idle network connections.
By default the HttpClient uses the proxy configuration available from the environment, see findProxyFromEnvironment(). To turn off the use of proxies all together set the findProxy property to null.
HttpClient client = new HttpClient(); client.findProxy = null;
Get and set the idle timeout of non-active persistent (keep-alive) connections. The default value is 15 seconds.
Set and get the default value of the User-Agent header for all requests generated by this HttpClient. The default value is Dart/<version> (dart:io).
If the userAgent is set to null, no default User-Agent header will be added to each request.
Sets the function to be called when a site is requesting authentication. The URL requested and the security realm from the server are passed in the arguments url and realm.
The function returns a Future which should complete when the authentication has been resolved. If credentials cannot be provided the Future should complete with false. If credentials are available the function should add these using addCredentials before completing the Future with the value true.
If the Future completes with true the request will be retried using the updated credentials. Otherwise response processing will continue normally.
Sets the function to be called when a proxy is requesting authentication. Information on the proxy in use and the security realm for the authentication are passed in the arguments host, port and realm.
The function returns a Future which should complete when the authentication has been resolved. If credentials cannot be provided the Future should complete with false. If credentials are available the function should add these using addProxyCredentials before completing the Future with the value true.
If the Future completes with true the request will be retried using the updated credentials. Otherwise response processing will continue normally.
Sets a callback that will decide whether to accept a secure connection with a server certificate that cannot be authenticated by any of our trusted root certificates.
When an secure HTTP request if made, using this HttpClient, and the server returns a server certificate that cannot be authenticated, the callback is called asynchronously with the X509Certificate object and the server's hostname and port. If the value of badCertificateCallback is null, the bad certificate is rejected, as if the callback returned false
If the callback returns true, the secure connection is accepted and the Future<HttpClientRequest> that was returned from the call making the request completes with a valid HttpRequest object. If the callback returns false, the Future<HttpClientRequest> completes with an exception.
If a bad certificate is received on a connection attempt, the library calls the function that was the value of badCertificateCallback at the time the the request is made, even if the value of badCertificateCallback has changed since then.
Sets the function used to resolve the proxy server to be used for opening a HTTP connection to the specified url. If this function is not set, direct connections will always be used.
The string returned by f must be in the format used by browser PAC (proxy auto-config) scripts. That is either
"DIRECT"
for using a direct connection or
"PROXY host:port"
for using the proxy server host on port port.
A configuration can contain several configuration elements separated by semicolons, e.g.
"PROXY host:port; PROXY host2:port2; DIRECT"
The static function findProxyFromEnvironment on this class can be used to implement proxy server resolving based on environment variables.
Add credentials to be used for authorizing HTTP requests.
Add credentials to be used for authorizing HTTP proxies.
Shutdown the HTTP client. If force is false (the default) the HttpClient will be kept alive until all active connections are done. If force is true any active connections will be closed to immediately release all resources. These closed connections will receive an onError callback to indicate that the client was shutdown. In both cases trying to establish a new connection after calling shutdown will throw an exception.
Function for resolving the proxy server to be used for a HTTP connection from the proxy configuration specified through environment variables.
The following environment variables are taken into account:
http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
http_proxy and HTTP_PROXY specify the proxy server to use for http:// urls. Use the format hostname:port. If no port is used a default of 1080 will be used. If both are set the lower case one takes precedence.
https_proxy and HTTPS_PROXY specify the proxy server to use for https:// urls. Use the format hostname:port. If no port is used a default of 1080 will be used. If both are set the lower case one takes precedence.
no_proxy and NO_PROXY specify a comma separated list of postfixes of hostnames for which not to use the proxy server. E.g. the value "localhost,127.0.0.1" will make requests to both "localhost" and "127.0.0.1" not use a proxy. If both are set the lower case one takes precedence.
To activate this way of resolving proxies assign this function to the findProxy property on the HttpClient.
HttpClient client = new HttpClient(); client.findProxy = HttpClient.findProxyFromEnvironment;If you don't want to use the system environment you can use a different one by wrapping the function.
HttpClient client = new HttpClient();
client.findProxy = (url) {
return HttpClient.findProxyFromEnvironment(
url, {"http_proxy": ..., "no_proxy": ...});
}
If a proxy requires authentication it is possible to configure the username and password as well. Use the format username:password@hostname:port to include the username and password. Alternatively the API addProxyCredentials can be used to set credentials for proxies which require authentication.
Opens a HTTP connection using the GET method.
The server is specified using host and port, and the path (including possible fragment and query) is specified using path.
See open for details.
Opens a HTTP connection using the GET method.
The URL to use is specified in url.
See openUrl for details.
Opens a HTTP connection.
The HTTP method to use is specified in method, the server is specified using host and port, and the path (including possible fragment and query) is specified using path.
The Host header for the request will be set to the value host:port. This can be overridden through the HttpClientRequest interface before the request is sent. NOTE if host is an IP address this will still be set in the Host header.
For additional information on the sequence of events during an HTTP transaction, and the objects returned by the futures, see the overall documentation for the class HttpClient.
Opens a HTTP connection.
The HTTP method is specified in method and the URL to use in url.
The Host header for the request will be set to the value host:port. This can be overridden through the HttpClientRequest interface before the request is sent. NOTE if host is an IP address this will still be set in the Host header.
For additional information on the sequence of events during an HTTP transaction, and the objects returned by the futures, see the overall documentation for the class HttpClient.
Opens a HTTP connection using the POST method.
The server is specified using host and port, and the path (including possible fragment and query) is specified using path.
See open for details.
Opens a HTTP connection using the POST method.
The URL to use is specified in url.
See openUrl for details.
Represents credentials for basic authentication.
Represents credentials for digest authentication. Digest authentication is only supported for servers using the MD5 algorithm and quality of protection (qop) of either "none" or "auth".
HTTP request for a client connection.
This object has a number of properties for setting up the HTTP header of the request. When the header has been set up the methods from the IOSink can be used to write the actual body of the HTTP request. When one of the IOSink methods is used for the first time the request header is send. Calling any methods that will change the header after it is sent will throw an exception.
When writing string data through the IOSink the encoding used will be determined from the "charset" parameter of the "Content-Type" header.
HttpClientRequest request = ...
request.headers.contentType
= new ContentType("application", "json", charset: "utf-8");
request.write(...); // Strings written will be UTF-8 encoded.
If no charset is provided the default of ISO-8859-1 (Latin 1) will be used.
HttpClientRequest request = ... request.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); request.write(...); // Strings written will be ISO-8859-1 encoded.If an unsupported encoding is used an exception will be thrown if using one of the write methods taking a string.
Gets and sets the content length of the request. If the size of the request is not known in advance set content length to -1, which is also the default.
Set this property to true if this request should automatically follow redirects. The default is true.
Automatic redirect will only happen for "GET" and "HEAD" requests and only for the status codes HttpHeaders.MOVED_PERMANENTLY (301), HttpStatus.FOUND (302), HttpStatus.MOVED_TEMPORARILY (302, alias for HttpStatus.FOUND), HttpStatus.SEE_OTHER (303) and HttpStatus.TEMPORARY_REDIRECT (307). For HttpStatus.SEE_OTHER (303) autmatic redirect will also happen for "POST" requests with the method changed to "GET" when following the redirect.
All headers added to the request will be added to the redirection request(s). However, any body send with the request will not be part of the redirection request(s).
Set this property to the maximum number of redirects to follow when followRedirects is true. If this number is exceeded the onError callback will be called with a RedirectException.
The default value is 5.
Gets and sets the requested persistent connection state. The default value is true.
Get information about the client connection. Returns null if the socket is not available.
Cookies to present to the server (in the 'cookie' header).
A HttpClientResponse future that will complete once the response is available. If an error occurs before the response is available, this future will complete with an error.
Returns the request headers.
The method of the request.
The uri of the request.
Close the request for input. Returns the value of done.
HTTP response for a client connection. The HttpClientResponse is a Stream of the body content of the response. Listen to the body to handle the data and be notified once the entire body is received.
Returns the certificate of the HTTPS server providing the response. Returns null if the connection is not a secure TLS or SSL connection.
Gets information about the client connection. Returns null if the socket is not available.
Returns the content length of the response body. Returns -1 if the size of the response body is not known in advance.
Cookies set by the server (from the 'set-cookie' header).
Returns the response headers.
Returns whether the status code is one of the normal redirect codes HttpStatus.MOVED_PERMANENTLY, HttpStatus.FOUND, HttpStatus.MOVED_TEMPORARILY, HttpStatus.SEE_OTHER and HttpStatus.TEMPORARY_REDIRECT.
Gets the persistent connection state returned by the server.
Returns the reason phrase associated with the status code.
Returns the series of redirects this connection has been through. The list will be empty if no redirects were followed. redirects will be updated both in the case of an automatic and a manual redirect.
Returns the status code.
Detach the underlying socket from the HTTP client. When the socket is detached the HTTP client will no longer perform any operations on it.
This is normally used when a HTTP upgrade is negotiated and the communication should continue with a different protocol.
Redirects this connection to a new URL. The default value for method is the method for the current request. The default value for url is the value of the HttpHeaders.LOCATION header of the current response. All body data must have been read from the current response before calling redirect.
All headers added to the request will be added to the redirection request. However, any body sent with the request will not be part of the redirection request.
If followLoops is set to true, redirect will follow the redirect, even if the URL was already visited. The default value is false.
redirect will ignore maxRedirects and will always perform the redirect.
Information about an HttpRequest, HttpResponse, HttpClientRequest, or HttpClientResponse connection.
Summary statistics about an HttpServers current socket connections.
Number of active connections where actual request/response processing is active.
Number of connections which are preparing to close. Note: These connections are also part of the active count as they might still be sending data to the client before finally closing.
Number of idle connections held by clients as persistent connections.
Total number of socket connections.
Utility functions for working with dates with HTTP specific date formats.
Format a date according to RFC-1123(http://tools.ietf.org/html/rfc1123 "RFC-1123"), e.g. Thu, 1 Jan 1970 00:00:00 GMT.
Parse a date string in either of the formats RFC-1123(http://tools.ietf.org/html/rfc1123 "RFC-1123"), RFC-850(http://tools.ietf.org/html/rfc850 "RFC-850") or ANSI C's asctime() format. These formats are listed here.
Thu, 1 Jan 1970 00:00:00 GMT Thursday, 1-Jan-1970 00:00:00 GMT Thu Jan 1 00:00:00 1970For more information see
RFC-2616 section 3.1.1 (http://tools.ietf.org/html/rfc2616#section-3.3.1 "RFC-2616 section 3.1.1").
Returns a string representation of this object.
Access to the HTTP headers for requests and responses. In some situations the headers will be immutable and the mutating methods will then throw exceptions.
For all operations on HTTP headers the header name is case-insensitive.
Gets and sets the chunked transfer encoding header value.
Gets and sets the content length header value.
Gets and sets the content type. Note that the content type in the header will only be updated if this field is set directly. Mutating the returned current value will have no effect.
Gets and sets the date. The value of this property will reflect the 'date' header.
Gets and sets the expiry date. The value of this property will reflect the 'expires' header.
Gets and sets the host part of the 'host' header for the connection.
Gets and sets the "if-modified-since" date. The value of this property will reflect the "if-modified-since" header.
Gets and sets the persistent connection header value.
Gets and sets the port part of the 'host' header for the connection.
Returns the list of values for the header named name. If there is no header with the provided name, null will be returned.
Adds a header value. The header named name will have the value value added to its list of values. Some headers are single valued, and for these adding a value will replace the previous value. If the value is of type DateTime a HTTP date format will be applied. If the value is a List each element of the list will be added separately. For all other types the default toString method will be used.
Enumerates the headers, applying the function f to each header. The header name passed in name will be all lower case.
Disables folding for the header named name when sending the HTTP header. By default, multiple header values are folded into a single header line by separating the values with commas. The 'set-cookie' header has folding disabled by default.
Removes a specific value for a header name. Some headers have system supplied values and for these the system supplied values will still be added to the collection of values for the header.
Removes all values for the specified header name. Some headers have system supplied values and for these the system supplied values will still be added to the collection of values for the header.
Sets a header. The header named name will have all its values cleared before the value value is added as its value.
Convenience method for the value for a single valued header. If there is no header with the provided name, null will be returned. If the header has more than one value an exception is thrown.
A server-side object that contains the content of and information about an HTTP request.
Note: Check out the http_server(http://pub.dartlang.org/packages/http_server) package, which makes working with the low-level dart:io HTTP server subsystem easier.
HttpRequest objects are generated by an HttpServer, which listens for HTTP requests on a specific host and port. For each request received, the HttpServer, which is a Stream, generates an HttpRequest object and adds it to the stream.
An HttpRequest object delivers the body content of the request as a stream of bytes. The object also contains information about the request, such as the method, URI, and headers.
In the following code, an HttpServer listens for HTTP requests and, within the callback function, uses the HttpRequest object's method property to dispatch requests.
final HOST = InternetAddress.LOOPBACK_IP_V4;
final PORT = 4040;
HttpServer.bind(HOST, PORT).then((_server) {
_server.listen((HttpRequest request) {
switch (request.method) {
case 'GET':
handleGetRequest(request);
break;
case 'POST':
...
}
},
onError: handleError); // listen() failed.
}).catchError(handleError);
Listen to the HttpRequest stream to handle the data and be notified once the entire body is received. An HttpRequest object contains an HttpResponse object, to which the server can write its response. For example, here's a skeletal callback function that responds to a request:
void handleGetRequest(HttpRequest req) {
HttpResponse res = req.response;
var body = [];
req.listen((List<int> buffer) => body.add(buffer),
onDone: () {
res.write('Received ${body.length} for request ');
res.write(' ${req.method}: ${req.uri.path}');
res.close();
},
onError: handleError);
}
The client certificate of the client making the request (read-only).
This value is null if the connection is not a secure TLS or SSL connection, or if the server does not request a client certificate, or if the client does not provide one.
Information about the client connection (read-only).
Returns null if the socket is not available.
The content length of the request body (read-only).
If the size of the request body is not known in advance, this value is -1.
The cookies in the request, from the Cookie headers (read-only).
The request headers (read-only).
The method, such as 'GET' or 'POST', for the request (read-only).
The persistent connection state signaled by the client (read-only).
The HTTP protocol version used in the request, either "1.0" or "1.1" (read-only).
The HttpResponse object, used for sending back the response to the client (read-only).
If the contentLength of the body isn't 0, and the body isn't being read, any write calls on the HttpResponse automatically drain the request body.
The session for the given request (read-only).
If the session is being initialized by this call, isNew is true for the returned session. See HttpServer.sessionTimeout on how to change default timeout.
The URI for the request (read-only).
This provides access to the path, query string, and fragment identifier for the request.
An HttpResponse represents the headers and data to be returned to a client in response to an HTTP request.
This object has a number of properties for setting up the HTTP header of the response. When the header has been set up the methods from the IOSink can be used to write the actual body of the HTTP response. When one of the IOSink methods is used for the first time the request header is send. Calling any methods that will change the header after it is sent will throw an exception.
When writing string data through the IOSink the encoding used will be determined from the "charset" parameter of the "Content-Type" header.
HttpResponse response = ...
response.headers.contentType
= new ContentType("application", "json", charset: "utf-8");
response.write(...); // Strings written will be UTF-8 encoded.
If no charset is provided the default of ISO-8859-1 (Latin 1) will be used.
HttpResponse response = ... response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); response.write(...); // Strings written will be ISO-8859-1 encoded.If an unsupported encoding is used an exception will be thrown if using one of the write methods taking a string.
Gets and sets the content length of the response. If the size of the response is not known in advance set the content length to -1 - which is also the default if not set.
Set and get the deadline for the response. The deadline is timed from the time it's set. Setting a new deadline will override any previous deadline. When a deadline is exceeded, the response will be closed and any further data ignored.
To disable a deadline, set the deadline to null.
The deadline is null by default.
Gets and sets the persistent connection state. The initial value of this property is the persistent connection state from the request.
Gets and sets the reason phrase. If no reason phrase is explicitly set a default reason phrase is provided.
Gets and sets the status code. Any integer value is accepted. For the official HTTP status codes use the fields from HttpStatus. If no status code is explicitly set the default value HttpStatus.OK is used.
Gets information about the client connection. Returns null if the socket is not available.
Cookies to set in the client (in the 'set-cookie' header).
Returns the response headers.
Detaches the underlying socket from the HTTP server. When the socket is detached the HTTP server will no longer perform any operations on it.
This is normally used when a HTTP upgrade request is received and the communication should continue with a different protocol.
Respond with a redirect to location.
The URI in location should be absolute, but there are no checks to enforce that.
By default the HTTP status code HttpStatus.MOVED_TEMPORARILY (302) is used for the redirect, but an alternative one can be specified using the status argument.
This method will also call close, and the returned future is the furure returned by close.
A server that delivers content, such as web pages, using the HTTP protocol.
The HttpServer is a Stream of HttpRequests. Each HttpRequest has an associated HttpResponse object as its HttpRequest.response member, and the server responds to a request by writing to that HttpResponse object.
Incomplete requests where all or parts of the header is missing, are ignored and no exceptions or HttpRequest objects are generated for them. Likewise, when writing to a HttpResponse, any Socket exceptions are ignored and any future writes are ignored.
The HttpRequest exposes the request headers, and provides the request body, if it exists, as a stream of data. If the body is unread, it'll be drained when the HttpResponse is being written to or closed.
The following example shows how to bind a HttpServer to a IPv6 InternetAddress on port 80, and listening to requests.
HttpServer.bind(InternetAddress.ANY_IP_V6, 80).then((server) {
server.listen((HttpRequest request) {
// Handle requests.
});
});
Get or set the timeout used for idle keep-alive connections. If no further request is seen within idleTimeout after the previous request was completed, the connection is droped.
Default is 120 seconds.
To disable, set idleTimeout to null.
Set and get the default value of the Server header for all responses generated by this HttpServer. The default value is Dart/<version> (dart:io).
If the serverHeader is set to null, no default Server header will be added to each response.
Returns the port that the server is listening on. This can be used to get the actual port used when a value of 0 for port is specified in the bind or bindSecure call.
Sets the timeout, in seconds, for sessions of this HttpServer. The default timeout is 20 minutes.
Attaches the HTTP server to an existing ServerSocket. When the HttpServer is closed, the HttpServer will just detach itself, closing current connections but not closing serverSocket.
Starts listening for HTTP requests on the specified address and port.
The address can either be a String or an InternetAddress. If address is a String, bind will perform a InternetAddress.lookup and use the first value in the list. To listen on the loopback adapter, which will allow only incoming connections from the local host, use the value InternetAddress.LOOPBACK_IP_V4 or InternetAddress.LOOPBACK_IP_V6. To allow for incoming connection from the network use either one of the values InternetAddress.ANY_IP_V4 or InternetAddress.ANY_IP_V6 to bind to all interfaces or the IP address of a specific interface.
If an IP version 6 (IPv6) address is used, both IP version 6 (IPv6) and version 4 (IPv4) connections will be accepted. To restrict this to version 6 (IPv6) only, use HttpServer.listenOn with a ServerSocket configured for IP version 6 connections only.
If port has the value 0 an ephemeral port will be chosen by the system. The actual port used can be retrieved using the port getter.
The optional argument backlog can be used to specify the listen backlog for the underlying OS listen setup. If backlog has the value of 0 (the default) a reasonable value will be chosen by the system.
The address can either be a String or an InternetAddress. If address is a String, bind will perform a InternetAddress.lookup and use the first value in the list. To listen on the loopback adapter, which will allow only incoming connections from the local host, use the value InternetAddress.LOOPBACK_IP_V4 or InternetAddress.LOOPBACK_IP_V6. To allow for incoming connection from the network use either one of the values InternetAddress.ANY_IP_V4 or InternetAddress.ANY_IP_V6 to bind to all interfaces or the IP address of a specific interface.
If an IP version 6 (IPv6) address is used, both IP version 6 (IPv6) and version 4 (IPv4) connections will be accepted. To restrict this to version 6 (IPv6) only, use HttpServer.listenOn with a ServerSocket configured for IP version 6 connections only.
If port has the value 0 an ephemeral port will be chosen by the system. The actual port used can be retrieved using the port getter.
The optional argument backlog can be used to specify the listen backlog for the underlying OS listen setup. If backlog has the value of 0 (the default) a reasonable value will be chosen by the system.
The certificate with nickname or distinguished name (DN) certificateName is looked up in the certificate database, and is used as the server certificate. If requestClientCertificate is true, the server will request clients to authenticate with a client certificate.
Permanently stops this HttpServer from listening for new connections. This closes this Stream of HttpRequests with a done event. The returned future completes when the server is stopped. For a server started using bind or bindSecure this means that the port listened on no longer in use.
Returns an HttpConnectionsInfo object summarizing the number of current connections handled by the server.
Gets the id for the current session.
Is true if the session has not been sent to the client yet.
Sets a callback that will be called when the session is timed out.
Destroys the session. This will terminate the session and any further connections with this id will be given a new id and session.
HTTP status codes.
Base class for all IO related exceptions.
Returns a string representation of this object.
Helper class to wrap a StreamConsumer<List<int>> and provide utility functions for writing to the StreamConsumer directly. The IOSink buffers the input given by all StringSink methods and will delay a addStream() until the buffer is flushed.
When the IOSink is bound to a stream (through addStream()) any call to the IOSink will throw a StateError. When the addStream() completes, the IOSink will again be open for all calls.
If data is added to the IOSink after the sink is closed, the data will be ignored. Use the done future to be notified when the IOSink is closed.
The Encoding used when writing strings. Depending on the underlying consumer this property might be mutable.
Get a future that will complete when all synchronous have completed, or an error happened. This future is identical to the future returned from close.
Writes the bytes uninterpreted to the consumer. While the call is synchronous, the data may be buffered until the underlying resource is ready. The data should not be modified after a call to add.
Writes an error to the consumer.
Adds all elements of the given stream to this.
Close the target.
The InternetAddress is an object reflecting either a remote or a local address. When combined with a port number, this represents a endpoint that a socket can connect to or a listening socket can bind to.
The type of the InternetAddress specified what IP protocol.
IP version 4 any address. Use this address when listening on all adapters IP addresses using IP version 4 (IPv4).
IP version 6 any address. Use this address when listening on all adapters IP addresses using IP version 6 (IPv6).
IP version 4 loopback address. Use this address when listening on or connecting to the loopback adapter using IP version 4 (IPv4).
IP version 6 loopback address. Use this address when listening on or connecting to the loopback adapter using IP version 6 (IPv6).
The resolved address of the host.
The host used to lookup the address.
Returns true if the InternetAddresss scope is a link-local.
Returns true if the InternetAddress is a loopback address.
Lookup a host, returning a Future of a list of InternetAddresss. If type is InternetAddressType.ANY, it will lookup both IP version 4 (IPv4) and IP version 6 (IPv6) addresses. If type is either InternetAddressType.IP_V4 or InternetAddressType.IP_V6 it will only lookup addresses of the specified type. The order of the list can, and most likely will, change over time.
Perform a reverse dns lookup on the address, creating a new InternetAddress where the host field set to the result.
InternetAddressType is the type an InternetAddress. Currently, IP version 4 (IPv4) and IP version 6 (IPv6) are supported.
Get the name of the type, e.g. "IP_V4" or "IP_V6".
Returns a string representation of this object.
Link objects are references to filesystem links.
Returns a Link instance whose path is the absolute path to this.
The absolute path is computed by prefixing a relative path with the current working directory, and returning an absolute path unchanged.
Creates a Link object.
Creates a symbolic link. Returns a Future<Link> that completes with the link when it has been created. If the link exists, the future will complete with an error.
On the Windows platform, this will only work with directories, and the target directory must exist. The link will be created as a Junction. Only absolute links will be created, and relative paths to the target will be converted to absolute paths by joining them with the path of the directory the link is contained in.
On other platforms, the posix symlink() call is used to make a symbolic link containing the string target. If target is a relative path, it will be interpreted relative to the directory containing the link.
Synchronously create the link. Calling createSync on an existing link will throw an exception.
On the Windows platform, this will only work with directories, and the target directory must exist. The link will be created as a Junction. Only absolute links will be created, and relative paths to the target will be converted to absolute paths.
On other platforms, the posix symlink() call is used to make a symbolic link containing the string target. If target is a relative path, it will be interpreted relative to the directory containing the link.
Renames this link. Returns a Future<Link> that completes with a Link instance for the renamed link.
If newPath identifies an existing link, that link is replaced. If newPath identifies an existing file or directory, the operation fails and the future completes with an exception.
Synchronously renames this link. Returns a Link instance for the renamed link.
If newPath identifies an existing link, that link is replaced. If newPath identifies an existing file or directory the operation fails and an exception is thrown.
Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all '..' and '.' path segments. resolveSymbolicLinks returns a Future<String>
resolveSymbolicLinks uses the operating system's native filesystem api to resolve the path, using the realpath function on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinks completes the returned Future with an FileException.
On Windows, symbolic links are resolved to their target before applying a '..' that follows, and on other platforms, the '..' is applied to the symbolic link without resolving it. The second behavior can be emulated on Windows by processing any '..' segments before calling resolveSymbolicLinks. One way of doing this is with the URI class: :new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();, since resolve removes '..' segments.
Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all '..' and '.' path segments.
resolveSymbolicLinksSync uses the operating system's native filesystem api to resolve the path, using the realpath function on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinksSync throws a FileException.
On Windows, symbolic links are resolved to their target before applying a '..' that follows, and on other platforms, the '..' is applied to the symbolic link without resolving it. The second behavior can be emulated on Windows by processing any '..' segments before calling resolveSymbolicLinks. One way of doing this is with the URI class: :new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();, since resolve removes '..' segments.
Gets the target of the link. Returns a future that completes with the path to the target.
If the returned target is a relative path, it is relative to the directory containing the link.
If the link does not exist, or is not a link, the future completes with a LinkException.
Synchronously gets the target of the link. Returns the path to the target.
If the returned target is a relative path, it is relative to the directory containing the link.
If the link does not exist, or is not a link, throws a LinkException.
Updates the link. Returns a Future<Link> that completes with the link when it has been updated. Calling update on a non-existing link will complete its returned future with an exception.
On the Windows platform, this will only work with directories, and the target directory must exist.
Synchronously updates the link. Calling updateSync on a non-existing link will throw an exception.
On the Windows platform, this will only work with directories, and the target directory must exist.
Returns a string representation of this object.
A NetworkInterface represent an active network interface on the current system. It contains a list of InternetAddresss, that's bound to the interface.
Get a list of InternetAddresss currently bound to this NetworkInterface.
Get the name of the NetworkInterface.
Query the system for NetworkInterfaces.
If includeLoopback is true, the returned list will include the loopback device. Default is false.
If includeLinkLocal is true, the list of addresses of the returned NetworkInterfaces, may include link local addresses. Default is false.
If type is either InternetAddressType.IP_V4 or InternetAddressType.IP_V6 it will only lookup addresses of the specified type. Default is InternetAddressType.ANY.
An OSError object holds information about an error from the operating system.
Constant used to indicate that no OS error code is available.
Error code supplied by the operating system. Will have the value noErrorCode if there is no error code associated with the error.
Error message supplied by the operating system. null if no message is associated with the error.
Creates an OSError object from a message and an errorCode.
Converts an OSError object to a string representation.
The Options object allows accessing the arguments which have been passed to the current isolate.
Returns a list of arguments that have been passed to this isolate. Any modifications to the list will be contained to the options object owning this list.
If the execution environment does not support arguments an empty list is returned.
Returns the path of the executable used to run the script in this isolate.
If the execution environment does not support executable an empty string is returned.
Returns the path of the script being run in this isolate.
If the executable environment does not support script an empty string is returned.
Returns the version of the current Dart runtime.
A newly constructed Options object contains the arguments exactly as they have been passed to the isolate.
The Platform class exposes details of the machine and operating system.
Get the environment for this process.
Environment variables on Windows are case-insensitive. The map returned on Windows is therefore case-insensitive and will convert all keys to upper case. On other platforms the returned map is a standard case-sensitive map.
Returns the path of the executable used to run the script in this isolate.
If the execution environment does not support executable an empty string is returned.
Returns the flags passed to the executable used to run the script in this isolate. These are the command-line flags between the executable name and the script name. Each fetch of executableArguments returns a new List, containing the flags passed to the executable.
Returns true if the operating system is Android.
Returns true if the operating system is Linux.
Returns true if the operating system is Mac OS.
Returns true if the operating system is Windows.
Get the local hostname for the system.
Get the number of processors of the machine.
Get a string (linux, macos, windows or android) representing the operating system.
Returns the value of the --package-root flag passed to the executable used to run the script in this isolate. This is the directory in which Dart packages are looked up.
If there is no --package-root flag, then the empty string is returned.
Get the path separator used by the operating system to separate components in file paths.
Returns the URI (in String form) of the script being run in this isolate. If the URI is relative it is relative to the file URI of the working directory of the VM when it was started.
If the executable environment does not support script an empty string is returned.
Returns the version of the current Dart runtime.
Returns a Future which completes with the exit code of the process when the process completes.
Throws an UnsupportedError if the process is non-interactive.
Returns the process id of the process.
Returns the standard error stream of the process as a Stream.
Throws an UnsupportedError if the process is non-interactive.
Returns the standard input stream of the process as an IOSink.
Throws an UnsupportedError if the process is non-interactive.
Returns the standard output stream of the process as a Stream.
Throws an UnsupportedError if the process is non-interactive.
On Windows, kill kills the process, ignoring the signal flag. On Posix systems, kill sends signal to the process. Depending on the signal giving, it'll have different meanings. When the process terminates as a result of calling kill onExit is called.
Returns true if the process is successfully killed (the signal is successfully sent). Returns false if the process could not be killed (the signal could not be sent). Usually, a false return value from kill means that the process is already dead.
Starts a process and runs it non-interactively to completion. The process run is executable with the specified arguments.
Use workingDirectory to set the working directory for the process. Note that the change of directory occurs before executing the process on some platforms, which may have impact when using relative paths for the executable and the arguments.
Use environment to set the environment variables for the process. If not set the environment of the parent process is inherited. Currently, only US-ASCII environment variables are supported and errors are likely to occur if an environment variable with code-points outside the US-ASCII range is passed in.
If includeParentEnvironment is true, the process's environment will include the parent process's environment, with environment taking precedence. Default is true.
If runInShell is true, the process will be spawned through a system shell. On Linux and Mac OS, /bin/sh is used, while %WINDIR%\system32\cmd.exe is used on Windows.
The encoding used for decoding stdout and stderr into text is controlled through stdoutEncoding and stderrEncoding. The default encoding is SYSTEM_ENCODING. If null is used no decoding will happen and the ProcessResult will hold binary data.
Returns a Future<ProcessResult> that completes with the result of running the process, i.e., exit code, standard out and standard in.
Starts a process and runs it to completion. This is a synchronous call and will block until the child process terminates.
The arguments are the same as for Process.run.
Returns a ProcessResult with the result of running the process, i.e., exit code, standard out and standard in.
Starts a process running the executable with the specified arguments. Returns a Future<Process> that completes with a Process instance when the process has been successfully started. That Process object can be used to interact with the process. If the process cannot be started the returned Future completes with an exception.
Use workingDirectory to set the working directory for the process. Note that the change of directory occurs before executing the process on some platforms, which may have impact when using relative paths for the executable and the arguments.
Use environment to set the environment variables for the process. If not set the environment of the parent process is inherited. Currently, only US-ASCII environment variables are supported and errors are likely to occur if an environment variable with code-points outside the US-ASCII range is passed in.
If includeParentEnvironment is true, the process's environment will include the parent process's environment, with environment taking precedence. Default is true.
If runInShell is true, the process will be spawned through a system shell. On Linux and Mac OS, /bin/sh is used, while %WINDIR%\system32\cmd.exe is used on Windows.
Users must read all data coming on the stdout and stderr streams of processes started with Process.start. If the user does not read all data on the streams the underlying system resources will not be freed since there is still pending data.
Contains the arguments provided for the process.
Contains the OS error code for the process exception if any.
Contains the executable provided for the process.
Contains the system message for the process exception if any.
Returns a string representation of this object.
ProcessResult represents the result of running a non-interactive process started with Process.run.
Exit code for the process.
Process id from the process.
Standard error from the process. The value used for the stderrEncoding argument to Process.run determins the type. If null was used this value is of type `List<int> otherwise it is of type String.
Standard output from the process. The value used for the stdoutEncoding argument to Process.run determins the type. If null was used this value is of type `List<int> otherwise it is of type String.
On Posix systems, ProcessSignal is used to send a specific signal to a child process, see Process.kill.
RandomAccessFile provides random access to the data in a file. RandomAccessFile objects are obtained by calling the open method on a File object.
Gets the path of the file underlying this RandomAccessFile.
Closes the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when it has been closed.
Synchronously closes the file.
Throws a FileException if the operation fails.
Flushes the contents of the file to disk. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the flush operation completes.
Synchronously flushes the contents of the file to disk.
Throws a FileException if the operation fails.
Gets the length of the file. Returns a Future<int> that completes with the length in bytes.
Synchronously gets the length of the file.
Throws a FileException if the operation fails.
Gets the current byte position in the file. Returns a Future<int> that completes with the position.
Synchronously gets the current byte position in the file.
Throws a FileException if the operation fails.
Reads bytes bytes from a file and returns the result as a list of bytes.
Reads a byte from the file. Returns a Future<int> that completes with the byte, or with -1 if end-of-file has been reached.
Synchronously reads a single byte from the file. If end-of-file has been reached -1 is returned.
Throws a FileException if the operation fails.
Reads into an existing List<int> from the file. If start is present, the bytes will be filled into buffer from at index start, otherwise index 0. If end is present, the end - start bytes will be read into buffer, otherwise up to buffer.length. If end == start nothing happends.
Returns a Future<int> that completes with the number of bytes read.
Synchronously reads into an existing List<int> from the file. If start is present, the bytes will be filled into buffer from at index start, otherwise index 0. If end is present, the end - start bytes will be read into buffer, otherwise up to buffer.length. If end == start nothing happends.
Throws a FileException if the operation fails.
Synchronously reads a maximum of bytes bytes from a file and returns the result in a list of bytes.
Throws a FileException if the operation fails.
Sets the byte position in the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the position has been set.
Synchronously sets the byte position in the file.
Throws a FileException if the operation fails.
Returns a human-readable string for this RandomAccessFile instance.
Truncates (or extends) the file to length bytes. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the truncation has been performed.
Synchronously truncates (or extends) the file to length bytes.
Throws a FileException if the operation fails.
Writes a single byte to the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.
Synchronously writes a single byte to the file. Returns the number of bytes successfully written.
Throws a FileException if the operation fails.
Writes from a List<int> to the file. It will read the buffer from index start to index end. If start is omitted, it'll start from index 0. If end is omitted, it will write to end of buffer.
Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.
Synchronously writes from a List<int> to the file. It will read the buffer from index start to index end. If start is omitted, it'll start from index 0. If end is omitted, it will write to the end of buffer.
Throws a FileException if the operation fails.
Writes a string to the file using the given Encoding. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.
Synchronously writes a single string to the file using the given Encoding.
Throws a FileException if the operation fails.
The RawSecureServerSocket is a server socket, providing a stream of low-level RawSecureSockets.
See RawSecureSocket for more info.
Returns the port used by this socket.
Returns a future for a RawSecureServerSocket. When the future completes the server socket is bound to the given address and port and has started listening on it.
The address can either be a String or an InternetAddress. If address is a String, bind will perform a InternetAddress.lookup and use the first value in the list. To listen on the loopback adapter, which will allow only incoming connections from the local host, use the value InternetAddress.LOOPBACK_IP_V4 or InternetAddress.LOOPBACK_IP_V6. To allow for incoming connection from the network use either one of the values InternetAddress.ANY_IP_V4 or InternetAddress.ANY_IP_V6 to bind to all interfaces or the IP address of a specific interface.
If port has the value 0 an ephemeral port will be chosen by the system. The actual port used can be retrieved using the port getter.
The optional argument backlog can be used to specify the listen backlog for the underlying OS listen setup. If backlog has the value of 0 (the default) a reasonable value will be chosen by the system.
Incoming client connections are promoted to secure connections, using the server certificate given by certificateName.
address must be given as a numeric address, not a host name.
certificateName is the nickname or the distinguished name (DN) of the certificate in the certificate database. It is looked up in the NSS certificate database set by SecureSocket.setCertificateDatabase. If certificateName contains "CN=", it is assumed to be a distinguished name. Otherwise, it is looked up as a nickname.
To request or require that clients authenticate by providing an SSL (TLS) client certificate, set the optional parameters requestClientCertificate or requireClientCertificate to true. Require implies request, so one doesn't need to specify both. To check whether a client certificate was received, check SecureSocket.peerCertificate after connecting. If no certificate was received, the result will be null.
Closes the socket. The returned future completes when the socket is fully closed and is no longer bound.
Adds a subscription to this stream.
On each data event from this stream, the subscriber's onData handler is called. If onData is null, nothing happens.
On errors from this stream, the onError handler is given a object describing the error.
If this stream closes, the onDone handler is called.
If cancelOnError is true, the subscription is ended when the first error is reported. The default is false.
RawSecureSocket provides a secure (SSL or TLS) network connection. Client connections to a server are provided by calling RawSecureSocket.connect. A secure server, created with RawSecureServerSocket, also returns RawSecureSocket objects representing the server end of a secure connection. The certificate provided by the server is checked using the certificate database provided in SecureSocket.initialize, and/or the default built-in root certificates.
Get the peer certificate for a connected RawSecureSocket. If this RawSecureSocket is the server end of a secure socket connection, peerCertificate will return the client certificate, or null, if no client certificate was received. If it is the client end, peerCertificate will return the server's certificate.
Constructs a new secure client socket and connect it to the given host on the given port. The returned Future is completed with the RawSecureSocket when it is connected and ready for subscription.
The certificate provided by the server is checked using the certificate database provided in SecureSocket.initialize, and/or the default built-in root certificates. If sendClientCertificate is set to true, the socket will send a client certificate if one is requested by the server. If certificateName is the nickname of a certificate in the certificate database, that certificate will be sent. If certificateName is null, which is the usual use case, an appropriate certificate will be searched for in the database and sent automatically, based on what the server says it will accept.
onBadCertificate is an optional handler for unverifiable certificates. The handler receives the X509Certificate, and can inspect it and decide (or let the user decide) whether to accept the connection or not. The handler should return true to continue the RawSecureSocket connection.
Renegotiate an existing secure connection, renewing the session keys and possibly changing the connection properties.
This repeats the SSL or TLS handshake, with options that allow clearing the session cache and requesting a client certificate.
Takes an already connected socket and starts client side TLS handshake to make the communication secure. When the returned future completes the RawSecureSocket has completed the TLS handshake. Using this function requires that the other end of the connection is prepared for TLS handshake.
If the socket already has a subscription, pass the existing subscription in the subscription parameter. The secure socket will take over the subscription and process any subsequent events. In most cases calling pause on this subscription before starting TLS handshake is the right thing to do.
If the host argument is passed it will be used as the host name for the TLS handshake. If host is not passed the host name from the socket will be used. The host can be either a String or an InternetAddress.
Calling this function will _not_ cause a DNS host lookup. If the host passed is a String the InternetAddress for the resulting SecureSocket will have this passed in host as its host value and the internet address of the already connected socket as its address value.
See connect for more information on the arguments.
Takes an already connected socket and starts server side TLS handshake to make the communication secure. When the returned future completes the RawSecureSocket has completed the TLS handshake. Using this function requires that the other end of the connection is going to start the TLS handshake.
If the socket already has a subscription, pass the existing subscription in the subscription parameter. The secure socket will take over the subscription and process any subsequent events.
If some of the data of the TLS handshake has already been read from the socket this data can be passed in the bufferedData parameter. This data will be processed before any other data available on the socket.
See RawSecureServerSocket.bind for more information on the arguments.
A RawServerSocket represents a listening socket, and provides a stream of low-level RawSocket objects, one for each connection made to the listening socket.
See RawSocket for more info.
Returns the port used by this socket.
Returns a future for a RawServerSocket. When the future completes the server socket is bound to the given address and port and has started listening on it.
The address can either be a String or an InternetAddress. If address is a String, bind will perform a InternetAddress.lookup and use the first value in the list. To listen on the loopback adapter, which will allow only incoming connections from the local host, use the value InternetAddress.LOOPBACK_IP_V4 or InternetAddress.LOOPBACK_IP_V6. To allow for incoming connection from the network use either one of the values InternetAddress.ANY_IP_V4 or InternetAddress.ANY_IP_V6 to bind to all interfaces or the IP address of a specific interface.
If an IP version 6 (IPv6) address is used, both IP version 6 (IPv6) and version 4 (IPv4) connections will be accepted. To restrict this to version 6 (IPv6) only, use v6Only to set version 6 only.
If port has the value 0 an ephemeral port will be chosen by the system. The actual port used can be retrieved using the port getter.
The optional argument backlog can be used to specify the listen backlog for the underlying OS listen setup. If backlog has the value of 0 (the default) a reasonable value will be chosen by the system.
Closes the socket. The returned future completes when the socket is fully closed and is no longer bound.
The RawSocket is a low-level interface to a socket, exposing the raw events signaled by the system. It's a Stream of RawSocketEvents.
Set or get, if the RawSocket should listen for RawSocketEvent.READ events. Default is true.
Set or get, if the RawSocket should listen for RawSocketEvent.WRITE events. Default is true. This is a one-shot listener, and writeEventsEnabled must be set to true again to receive another write event.
Returns the InternetAddress used to connect this socket.
Returns the port used by this socket.
Returns the remote host connected to by this socket.
Returns the remote port connected to by this socket.
Returns the number of received and non-read bytes in the socket that can be read.
Closes the socket. Returns a Future that completes with this when the underlying connection is completely destroyed.
Calling close will never throw an exception and calling it several times is supported. Calling close can result in a RawSocketEvent.READ_CLOSED event.
Creates a new socket connection to the host and port and returns a Future that will complete with either a RawSocket once connected or an error if the host-lookup or connection failed.
host can either be a String or an InternetAddress. If host is a String, connect will perform a InternetAddress.lookup and use the first value in the list.
Read up to len bytes from the socket. This function is non-blocking and will only return data if data is available. The number of bytes read can be less then len if fewer bytes are available for immediate reading. If no data is available null is returned.
Use setOption to customize the RawSocket. See SocketOption for available options.
Returns true if the option was set successfully, false otherwise.
Shutdown the socket in the direction. Calling shutdown will never throw an exception and calling it several times is supported. Calling shutdown with either SocketDirection.BOTH or SocketDirection.RECEIVE can result in a RawSocketEvent.READ_CLOSED event.
Writes up to count bytes of the buffer from offset buffer offset to the socket. The number of successfully written bytes is returned. This function is non-blocking and will only write data if buffer space is available in the socket.
The default value for offset is 0, and the default value for count is buffer.length - offset.
Events for the RawSocket.
Returns a string representation of this object.
Returns a string representation of this object.
Redirect information.
Returns the location for the redirect.
Returns the method used for the redirect.
Returns the status code used for the redirect.
The SecureServerSocket is a server socket, providing a stream of high-level Sockets.
See SecureSocket for more info.
Returns the port used by this socket.
Returns a future for a SecureServerSocket. When the future completes the server socket is bound to the given address and port and has started listening on it.
The address can either be a String or an InternetAddress. If address is a String, bind will perform a InternetAddress.lookup and use the first value in the list. To listen on the loopback adapter, which will allow only incoming connections from the local host, use the value InternetAddress.LOOPBACK_IP_V4 or InternetAddress.LOOPBACK_IP_V6. To allow for incoming connection from the network use either one of the values InternetAddress.ANY_IP_V4 or InternetAddress.ANY_IP_V6 to bind to all interfaces or the IP address of a specific interface.
If port has the value 0 an ephemeral port will be chosen by the system. The actual port used can be retrieved using the port getter.
The optional argument backlog can be used to specify the listen backlog for the underlying OS listen setup. If backlog has the value of 0 (the default) a reasonable value will be chosen by the system.
Incoming client connections are promoted to secure connections, using the server certificate given by certificateName.
address must be given as a numeric address, not a host name.
certificateName is the nickname or the distinguished name (DN) of the certificate in the certificate database. It is looked up in the NSS certificate database set by SecureSocket.setCertificateDatabase. If certificateName contains "CN=", it is assumed to be a distinguished name. Otherwise, it is looked up as a nickname.
To request or require that clients authenticate by providing an SSL (TLS) client certificate, set the optional parameter requestClientCertificate or requireClientCertificate to true. Requiring a certificate implies requesting a certificate, so one doesn't need to set both to true. To check whether a client certificate was received, check SecureSocket.peerCertificate after connecting. If no certificate was received, the result will be null.
Closes the socket. The returned future completes when the socket is fully closed and is no longer bound.
Adds a subscription to this stream.
On each data event from this stream, the subscriber's onData handler is called. If onData is null, nothing happens.
On errors from this stream, the onError handler is given a object describing the error.
If this stream closes, the onDone handler is called.
If cancelOnError is true, the subscription is ended when the first error is reported. The default is false.
A high-level class for communicating securely over a TCP socket, using TLS and SSL. The SecureSocket exposes both a Stream and an IOSink interface, making it ideal for using together with other Streams.
Get the peer certificate for a connected SecureSocket. If this SecureSocket is the server end of a secure socket connection, peerCertificate will return the client certificate, or null, if no client certificate was received. If it is the client end, peerCertificate will return the server's certificate.
Constructs a new secure client socket and connect it to the given host on port port. The returned Future will complete with a SecureSocket that is connected and ready for subscription.
If sendClientCertificate is set to true, the socket will send a client certificate if one is requested by the server.
If certificateName is the nickname of a certificate in the certificate database, that certificate will be sent.
If certificateName is null, which is the usual use case, an appropriate certificate will be searched for in the database and sent automatically, based on what the server says it will accept.
onBadCertificate is an optional handler for unverifiable certificates. The handler receives the X509Certificate, and can inspect it and decide (or let the user decide) whether to accept the connection or not. The handler should return true to continue the SecureSocket connection.
Initializes the NSS library. If initialize is not called, the library is automatically initialized as if initialize were called with no arguments. If initialize is called more than once, or called after automatic initialization has happened (when a secure connection is made), then a TlsException is thrown.
The optional argument database is the path to a certificate database directory containing root certificates for verifying certificate paths on client connections, and server certificates to provide on server connections. The argument password should be used when creating secure server sockets, to allow the private key of the server certificate to be fetched. If useBuiltinRoots is true (the default), then a built-in set of root certificates for trusted certificate authorities is merged with the certificates in the database. The list of built-in root certificates, and documentation about this default database, is available at http://www.mozilla.org/projects/security/certs/included/ .
If the database argument is omitted, then only the builtin root certificates are used. If useBuiltinRoots is also false, then no certificates are available.
Examples: 1) Use only the builtin root certificates:
SecureSocket.initialize(); or2) Use a specified database directory and the builtin roots:
SecureSocket.initialize(database: 'path/to/my/database',
password: 'my_password');
3) Use a specified database directory, without builtin roots: SecureSocket.initialize(database: 'path/to/my/database',
password: 'my_password'.
useBuiltinRoots: false);
The database should be an NSS certificate database directory containing a cert9.db file, not a cert8.db file. This version of the database can be created using the NSS certutil tool with "sql:" in front of the absolute path of the database directory, or setting the environment variable [NSS_DEFAULT_DB_TYPE] to "sql".
Renegotiate an existing secure connection, renewing the session keys and possibly changing the connection properties.
This repeats the SSL or TLS handshake, with options that allow clearing the session cache and requesting a client certificate.
Takes an already connected socket and starts client side TLS handshake to make the communication secure. When the returned future completes the SecureSocket has completed the TLS handshake. Using this function requires that the other end of the connection is prepared for TLS handshake.
If the socket already has a subscription, this subscription will no longer receive and events. In most cases calling pause on this subscription before starting TLS handshake is the right thing to do.
If the host argument is passed it will be used as the host name for the TLS handshake. If host is not passed the host name from the socket will be used. The host can be either a String or an InternetAddress.
Calling this function will _not_ cause a DNS host lookup. If the host passed is a String the InternetAddress for the resulting SecureSocket will have the passed in host as its host value and the internet address of the already connected socket as its address value.
See connect for more information on the arguments.
Takes an already connected socket and starts server side TLS handshake to make the communication secure. When the returned future completes the SecureSocket has completed the TLS handshake. Using this function requires that the other end of the connection is going to start the TLS handshake.
If the socket already has a subscription, this subscription will no longer receive and events. In most cases calling pause on this subscription before starting TLS handshake is the right thing to do.
If some of the data of the TLS handshake has already been read from the socket this data can be passed in the bufferedData parameter. This data will be processed before any other data available on the socket.
See SecureServerSocket.bind for more information on the arguments.
A ServerSocket represents a listening socket, and provides a stream of Socket objects, one for each connection made to the listening socket.
See Socket for more info.
Returns the port used by this socket.
Returns a future for a ServerSocket. When the future completes the server socket is bound to the given address and port and has started listening on it.
The address can either be a String or an InternetAddress. If address is a String, bind will perform a InternetAddress.lookup and use the first value in the list. To listen on the loopback adapter, which will allow only incoming connections from the local host, use the value InternetAddress.LOOPBACK_IP_V4 or InternetAddress.LOOPBACK_IP_V6. To allow for incoming connection from the network use either one of the values InternetAddress.ANY_IP_V4 or InternetAddress.ANY_IP_V6 to bind to all interfaces or the IP address of a specific interface.
If an IP version 6 (IPv6) address is used, both IP version 6 (IPv6) and version 4 (IPv4) connections will be accepted. To restrict this to version 6 (IPv6) only, use v6Only to set version 6 only.
If port has the value 0 an ephemeral port will be chosen by the system. The actual port used can be retrieved using the port getter.
The optional argument backlog can be used to specify the listen backlog for the underlying OS listen setup. If backlog has the value of 0 (the default) a reasonable value will be chosen by the system.
Closes the socket. The returned future completes when the socket is fully closed and is no longer bound.
A high-level class for communicating over a TCP socket.
The Socket exposes both a Stream and a IOSink interface, making it ideal for using together with other Streams.
Returns the InternetAddress used to connect this socket.
Returns the port used by this socket.
Returns the remote host connected to by this socket.
Returns the remote port connected to by this socket.
Creats a new socket connection to the host and port and returns a Future that will complete with either a Socket once connected or an error if the host-lookup or connection failed.
host can either be a String or an InternetAddress. If host is a String, connect will perform a InternetAddress.lookup and use the first value in the list.
Destroy the socket in both directions. Calling destroy will make the send a close event on the stream and will no longer react on data being piped to it.
Call close(inherited from IOSink) to only close the Socket for sending data.
Use setOption to customize the RawSocket. See SocketOption for available options.
Returns true if the option was set successfully, false otherwise.
The SocketDirection is used as a parameter to Socket.close and RawSocket.close to close a socket in the specified direction(s).
Returns a string representation of this object.
The SocketOption is used as a parameter to Socket.setOption and RawSocket.setOption to set customize the behaviour of the underlying socket.
Enable or disable no-delay on the socket. If TCP_NODELAY is enabled, the socket will not buffer data internally, but instead write each data chunk as an invidual TCP packet.
TCP_NODELAY is disabled by default.
Stdin allows both synchronous and asynchronous reads from the standard input stream.
Mixing synchronous and asynchronous reads is undefined.
Enable or disable echo mode on the Stdin.
If disabled, input from to console will not be echoed.
Default depends on the parent process, but usually enabled.
Enable or disable line mode on the Stdin.
If enabled, characters are delayed until a new-line character is entered. If disabled, characters will be available as typed.
Default depends on the parent process, but usually enabled.
Synchronously read a byte from stdin. This call will block until a byte is available.
If at end of file, -1 is returned.
Synchronously read a line from stdin. This call will block until a full line is available. The line will contain the newline character(s).
If end-of-file is reached, null is returned.
If end-of-file is reached after some data has already been read, that data is returned.
Returns a string representation of this object.
The system encoding is the current code page on Windows and UTF-8 on Linux and Mac.
A secure networking exception caused by a failure in the TLS/SSL protocol.
Returns a string representation of this object.
A two-way HTTP communication object for client or server applications.
The stream exposes the messages received. A text message will be of type String and a binary message will be of type List<int>.
Possible states of the connection.
Set and get the interval for sending ping signals. If a ping message is not answered by a pong message from the peer, the WebSocket is assumed disconnected and the connection is closed with a WebSocketStatus.GOING_AWAY close code. When a ping signal is sent, the pong message must be received within pingInterval.
There are never two outstanding pings at any given time, and the next ping timer starts when the pong is received.
Set the pingInterval to null to disable sending ping messages.
The default value is null.
The close code set when the web socket connection is closed. If there is no close code available this property will be null
The close reason set when the web socket connection is closed. If there is no close reason available this property will be null
The extensions property is initially the empty string. After the web socket connection is established this string reflects the extensions used by the server.
The protocol property is initially the empty string. After the web socket connection is established the value is the subprotocol selected by the server. If no subprotocol is negotiated the value will remain null.
Returns the current state of the connection.
Sends data on the web socket connection. The data in data must be either a String, or a List<int> holding bytes.
Sends data from a stream on web socket connection. Each data event from stream will be send as a single WebSocket frame. The data from stream must be either Strings, or List<int>s holding bytes.
Closes the web socket connection. Set the optional code and reason arguments to send close information to the remote peer. If they are omitted, the peer will see WebSocketStatus.NO_STATUS_RECEIVED code with no reason.
Create a new web socket connection. The URL supplied in url must use the scheme ws or wss. The protocols argument is either a String or List<String> specifying the subprotocols the client is willing to speak.
Returns a string representation of this object.
Web socket status codes used when closing a web socket connection.
The WebSocketTransformer provides the ability to upgrade a HttpRequest to a WebSocket connection. It supports both upgrading a single HttpRequest and upgrading a stream of HttpRequests.
To upgrade a single HttpRequest use the static upgrade() method.
HttpServer server;
server.listen((request) {
if (...) {
WebSocketTransformer.upgrade(request).then((websocket) {
...
});
} else {
// Do normal HTTP request processing.
}
});
To transform a stream of HttpRequest events as it implements a stream transformer that transforms a stream of HttpRequest into a stream of WebSockets by upgrading each HttpRequest from the HTTP or HTTPS server, to the WebSocket protocol.
server.transform(new WebSocketTransformer()).listen((webSocket) => ...);This transformer strives to implement web sockets as specified by RFC6455.
Checks whether the request is a valid WebSocket upgrade request.
Upgrades a HttpRequest to a WebSocket connection. If the request is not a valid web socket upgrade request a HTTP response with status code 500 will be returned. Otherwise the returned future will complete with the WebSocket when the upgrade pocess is complete.
X509Certificate represents an SSL certificate, with accessors to get the fields of the certificate.
The ZLibCodec encodes raw bytes to ZLib compressed bytes and decodes ZLib compressed bytes to raw bytes.
The compression level of the ZLibCodec.
Get a Converter for decoding ZLib compressed data.
Get a Converter for encoding to ZLib compressed data.
The compression-level can be set in the range of 1..10, with 6 being the default compression level. Levels above 6 will have higher compression rates at the cost of more CPU and memory usage. Levels below 6 will use less CPU and memory, but at the cost of lower compression rates.
The ZLibDecoder is the decoder used by ZLibCodec and GZipCodec to decompress data.
Create a new ZLibEncoder converter.
Convert a list of bytes using the options given to the ZLibDecoder constructor.
Start a chunked conversion. While it accepts any ChunkedConversionSink taking List<int>'s, the optimal sink to be passed as sink is a ByteConversionSink.
The ZLibEncoder is the encoder used by ZLibCodec and GZipCodec to compress data.
If gzip is true, GZip frames will be added to the compressed data.
The compression level used by the encoder.
Create a new ZLibEncoder converter. If the gzip flag is set, the encoder will wrap the encoded ZLib data in GZip frames.
Convert a list of bytes using the options given to the ZLibEncoder constructor.
Start a chunked conversion using the options given to the ZLibEncoder constructor. While it accepts any ChunkedConversionSink taking List<int>'s, the optimal sink to be passed as sink is a ByteConversionSink.