ISimpleHttp

Description

interface Tinman.Core.IO.ISimpleHttp

Derived from

IDisposableGeneric<ISimpleHttp>

Extended by

SimpleHttp abstract

The ISimpleHttp interface provides methods for performing thread-safe synchronous HTTP/HTTPS requests for binary resources, images and plain text.

When a ISimpleHttp object is disposed, all pending requests will be cancelled, as if Cancel had been called prior to IDisposable.Dispose.

Public / Methods

Cancel


public method Cancel → ()

Cancels all pending HTTP requests.

A cancelled HTTP request has a SimpleHttpResult.StatusCode of 0 and an SimpleHttpResult.ErrorCode of IOError.Cancelled.

Get


[OwnerReturn] [ThreadSafe]
public method Get → (2)

url in : string

[not-empty]
The URL of the resource.

result out : SimpleHttpResult

The request result status.

returns → ByteBuffer

The buffer that holds the resource content between ByteBuffer.Position and ByteBuffer.Limit or null if SimpleHttpResult.IsSuccess is false.

Performs an HTTP/1.0 GET request on the given resource.

Get​Bytes


[ThreadSafe]
public method GetBytes → (5)

url in : string

[not-empty]
The URL of the resource.

buffer in : ByteBuffer

[not-null]
The output buffer. The ByteBuffer position will not be modified by this method.

bufferOffset opt : int32 = -1

[>=-1]
Absolute offset into the output buffer in to the first byte to write. Bytes are written up to the buffer capacity (see ByteBuffer.Capacity). If set to -1, the current buffer position (see ByteBuffer.Position) and buffer limit (see ByteBuffer.Limit) will be used to define the range of bytes that will be written.

from opt : int64 = 0

[>=0]
Start of byte range (inclusive).

to opt : int64 = 0

[>=0]
End of byte range (exclusive).

returns → SimpleHttpResult

The request result status.

Performs an HTTP/1.1 GET request on the given binary resource byte range.

On success (see SimpleHttpResult.IsSuccess), exactly SimpleHttpResult.Length bytes have been written to buffer in, without updating its position. If the given byte range is empty (i.e. to opt is less than or equal to from opt), the whole resource content is requested.

The length of the requested data (see from opt and to opt) is clamped to the maximum number of bytes that can be written to the buffer in output range. Less data than requested may be written if the given byte range exceeds the size of the resource.

If the byte range is not empty and lies outside the file range, the HTTP server is supposed to return the status code 416 Requested Range Not Satisfiable. This must be taken into account when GET-ing consecutive byte chunks up to the end-of-file, since the from opt parameter could become equal to the file size.

Get​Image


[ThreadSafe]
public method GetImage → (7)

url in : string

[not-empty]
The URL of the image resource.

width in : int32

[>=0]
The expected width of the image, in pixels.

height in : int32

[>=0]
The expected height of the image, in pixels.

pixels in : int64 [ ]

[not-null]
Output array for image image pixels (see Colors).

offset in : int32

[>=0]
Offset into pixels in to top-left output pixel.

stride in : int32

[>=0]
Distance between adjacent pixels rows in pixels in.

defaultSrgb opt : bool = true

If the downloaded image data does not specify a color-space, assume that it is using the sRGB color-space and perform gamma correction accordingly.

returns → SimpleHttpResult

The request result status.

Performs an HTTP/1.0 GET request on the given image resource.

This method is intended to be used for downloading image tiles, which have a uniform size that is known beforehand. To download regular image resources, use Get and load the image content in a separate step.

Get​Text


[ThreadSafe]
public method GetText → (2)

url in : string

[not-empty]
The URL of the resource.

buffer in : StringBuilder

[not-null]
The output buffer.

returns → SimpleHttpResult

The request result status.

Performs an HTTP/1.0 GET request on the given text resource.

Head


[ThreadSafe]
public method Head → (1)

url in : string

[not-empty]
The URL of the resource.

returns → SimpleHttpResult

The request result status.

Performs an HTTP/1.0 HEAD request on the given resource.

Public / Attributes

Attempts


public attribute Attempts → (get,set)

value : int32

[>=1]
The number of attempts.

The number of attempts to make for accessing an HTTP resource.

The default value is 3.

Can​Get


public attribute CanGet → (get)

value : bool

true if Get is supported,
false if it is not and will always fail with an error code.

Does this ISimpleHttp object support Get?

Can​Get​Bytes


public attribute CanGetBytes → (get)

value : bool

true if GetBytes is supported,
false if it is not and will always fail with an error code.

Does this ISimpleHttp object support GetBytes?

Can​Get​Image


public attribute CanGetImage → (get)

value : bool

true if GetImage is supported,
false if it is not and will always fail with an error code.

Does this ISimpleHttp object support GetImage?

Can​Get​Text


public attribute CanGetText → (get)

value : bool

true if GetText is supported,
false if it is not and will always fail with an error code.

Does this ISimpleHttp object support GetText?

Can​Head


public attribute CanHead → (get)

value : bool

true if Head is supported,
false if it is not and will always fail with an error code.

Does this ISimpleHttp object support Head?

Get​Text​Task


public attribute GetTextTask → (get)

value : ITask<string, string>

[not-null]
The task object.

Returns a new ITask object, for calling GetText asynchronously.

Head​Task


public attribute HeadTask → (get)

value : ITask<string, SimpleHttpResult>

[not-null]
The task object.

Returns a new ITask object, for calling Head asynchronously.

Timeout


public attribute Timeout → (get,set)

value : int32

[>0]
The timeout value, in milliseconds.

The request timeout.

The default timeout value is 15000 (i.e. 15 seconds).

An HTTP request that has timed out has a SimpleHttpResult.StatusCode of 0 and an SimpleHttpResult.ErrorCode of IOError.TimeOut

User​Agent


public attribute UserAgent → (get)

value : string

[not-empty]
The user agent string.

The user agent string.