Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class HttpClientBase

    Base class for Http clients.

    Inheritance
    object
    HttpClientBase
    HttpReplicator
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Replicator.Http
    Assembly: Lucene.Net.Replicator.dll
    Syntax
    public abstract class HttpClientBase : IDisposable
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Constructors

    HttpClientBase(string, int, string, HttpMessageHandler)

    Creates a new HttpClientBase with the given host, port and path.

    Declaration
    protected HttpClientBase(string host, int port, string path, HttpMessageHandler messageHandler = null)
    Parameters
    Type Name Description
    string host

    The host that the client should retrieve data from.

    int port

    The port to be used to connect on.

    string path

    The path to the replicator on the host.

    HttpMessageHandler messageHandler

    Optional, The HTTP handler stack to use for sending requests, defaults to null.

    Remarks

    The host, port and path parameters are normalized to http://{host}:{port}{path}, if path is null or empty it defaults to /.

    A HttpMessageHandler is taken as an optional parameter as well, if this is not provided it defaults to null. In this case the internal HttpClient will default to use a HttpClientHandler.

    HttpClientBase(string, HttpClient)

    Creates a new HttpClientBase with the given url and HttpClient.

    Declaration
    protected HttpClientBase(string url, HttpClient client)
    Parameters
    Type Name Description
    string url
    HttpClient client

    The HttpClient to use make remote http calls.

    Remarks

    This allows full controll over how the HttpClient is created, prefer the HttpClientBase(string, HttpMessageHandler) over this unless you know you need the control of the HttpClient.

    HttpClientBase(string, HttpMessageHandler)

    Creates a new HttpClientBase with the given url.

    Declaration
    protected HttpClientBase(string url, HttpMessageHandler messageHandler = null)
    Parameters
    Type Name Description
    string url

    The full url, including with host, port and path.

    HttpMessageHandler messageHandler

    Optional, The HTTP handler stack to use for sending requests.

    Remarks

    A HttpMessageHandler is taken as an optional parameter as well, if this is not provided it defaults to null. In this case the internal HttpClient will default to use a HttpClientHandler.

    Fields

    DEFAULT_CONNECTION_TIMEOUT

    Base class for Http clients.

    Declaration
    [Obsolete("Use DEFAULT_TIMEOUT instead.  This extension method will be removed in 4.8.0 release candidate.")]
    public const int DEFAULT_CONNECTION_TIMEOUT = 1000
    Field Value
    Type Description
    int
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    DEFAULT_TIMEOUT

    Default request timeout for this client (100 seconds). Timeout.

    Declaration
    public static readonly TimeSpan DEFAULT_TIMEOUT
    Field Value
    Type Description
    TimeSpan
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Properties

    IsDisposed

    Returns true if this instance was Dispose(bool)ed, otherwise returns false. Note that if you override Dispose(bool), you must call Dispose(bool) on the base class, in order for this instance to be properly disposed.

    Declaration
    public bool IsDisposed { get; }
    Property Value
    Type Description
    bool
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Timeout

    Gets or Sets the connection timeout for this client, in milliseconds. This setting is used to modify Timeout.

    Declaration
    public virtual TimeSpan Timeout { get; set; }
    Property Value
    Type Description
    TimeSpan
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Url

    The URL to execute requests against.

    Declaration
    protected string Url { get; }
    Property Value
    Type Description
    string
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Methods

    Dispose()

    Disposes this HttpClientBase. This disposes the underlying HttpClient.

    Declaration
    public void Dispose()
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Dispose(bool)

    Disposes this HttpClientBase. When called with

    true
    , this disposes the underlying HttpClient.
    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    DoAction<T>(HttpResponseMessage, bool, Func<T>)

    Do a specific action and validate after the action that the status is still OK, and if not, attempt to extract the actual server side exception. Optionally release the response at exit, depending on consume parameter.

    Declaration
    protected virtual T DoAction<T>(HttpResponseMessage response, bool consume, Func<T> call)
    Parameters
    Type Name Description
    HttpResponseMessage response
    bool consume
    Func<T> call
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    DoAction<T>(HttpResponseMessage, Func<T>)

    Calls the overload DoAction<T>(HttpResponseMessage, bool, Func<T>) passing true to consume.

    Declaration
    protected virtual T DoAction<T>(HttpResponseMessage response, Func<T> call)
    Parameters
    Type Name Description
    HttpResponseMessage response
    Func<T> call
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    EnsureOpen()

    Throws ObjectDisposedException if this client is already disposed.

    Declaration
    protected void EnsureOpen()
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Exceptions
    Type Condition
    ObjectDisposedException

    client is already disposed.

    ExecuteGet(string, params string[])

    Internal: Execute a request and return its result. The parameters argument is treated as: name1,value1,name2,value2,...

    Declaration
    protected virtual HttpResponseMessage ExecuteGet(string request, params string[] parameters)
    Parameters
    Type Name Description
    string request
    string[] parameters
    Returns
    Type Description
    HttpResponseMessage
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    ExecutePost(string, object, params string[])

    Internal: Execute a request and return its result. The parameters argument is treated as: name1,value1,name2,value2,...

    Declaration
    protected virtual HttpResponseMessage ExecutePost(string request, object entity, params string[] parameters)
    Parameters
    Type Name Description
    string request
    object entity
    string[] parameters
    Returns
    Type Description
    HttpResponseMessage
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    GetResponseStream(HttpResponseMessage)

    Internal utility: input stream of the provided response.

    Declaration
    public virtual Stream GetResponseStream(HttpResponseMessage response)
    Parameters
    Type Name Description
    HttpResponseMessage response
    Returns
    Type Description
    Stream
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Exceptions
    Type Condition
    IOException

    GetResponseStream(HttpResponseMessage, bool)

    Internal utility: input stream of the provided response, which optionally consumes the response's resources when the input stream is exhausted.

    Declaration
    public virtual Stream GetResponseStream(HttpResponseMessage response, bool consume)
    Parameters
    Type Name Description
    HttpResponseMessage response
    bool consume
    Returns
    Type Description
    Stream
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Exceptions
    Type Condition
    IOException

    ResponseInputStream(HttpResponseMessage)

    Internal utility: input stream of the provided response.

    Declaration
    [Obsolete("Use GetResponseStream(HttpResponseMessage) instead.  This extension method will be removed in 4.8.0 release candidate.")]
    public virtual Stream ResponseInputStream(HttpResponseMessage response)
    Parameters
    Type Name Description
    HttpResponseMessage response
    Returns
    Type Description
    Stream
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Exceptions
    Type Condition
    IOException

    ResponseInputStream(HttpResponseMessage, bool)

    Internal utility: input stream of the provided response, which optionally consumes the response's resources when the input stream is exhausted.

    Declaration
    [Obsolete("Use GetResponseStream(HttpResponseMessage, bool) instead.  This extension method will be removed in 4.8.0 release candidate.")]
    public virtual Stream ResponseInputStream(HttpResponseMessage response, bool consume)
    Parameters
    Type Name Description
    HttpResponseMessage response
    bool consume
    Returns
    Type Description
    Stream
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Exceptions
    Type Condition
    IOException

    ThrowKnownError(HttpResponseMessage)

    Throws an exception for any errors.

    Declaration
    protected virtual void ThrowKnownError(HttpResponseMessage response)
    Parameters
    Type Name Description
    HttpResponseMessage response
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    VerifyStatus(HttpResponseMessage)

    Internal: Verifies the response status and if not successful throws an exception.

    Declaration
    protected virtual void VerifyStatus(HttpResponseMessage response)
    Parameters
    Type Name Description
    HttpResponseMessage response
    Remarks

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Exceptions
    Type Condition
    IOException

    IO Error happened at the server, check inner exception for details.

    HttpRequestException

    Unknown error received from the server.

    Implements

    IDisposable
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.