Skip to content

Commit

Permalink
fix endpoint and headerslist
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Oct 30, 2024
1 parent fbbb773 commit 2f0ebbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
35 changes: 25 additions & 10 deletions src/Elastic.Transport/Components/Pipeline/RequestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,39 @@ namespace Elastic.Transport;
/// </remarks>
public record Endpoint(in EndpointPath Path, Node Node)
{
/// <summary>
/// The <see cref="Uri" /> for the request.
/// </summary>
public Uri Uri { get; } = new(Node.Uri, Path.PathAndQuery);
/// <summary> Represents an empty endpoint used as a default or placeholder instance of <see cref="Endpoint"/>. </summary>
public static Endpoint Empty(in EndpointPath path) => new(path, EmptyNode);

private static readonly Node EmptyNode = new(new Uri("http://empty.example"));

/// <summary> Indicates whether the endpoint is an empty placeholder instance. </summary>
public bool IsEmpty => Node == EmptyNode;

/// <summary> The <see cref="Uri" /> for the request. </summary>
public Uri Uri { get; private init; } = new(Node.Uri, Path.PathAndQuery);

/// <summary> The HTTP method used for the request (e.g., GET, POST, PUT, DELETE, HEAD). </summary>
public HttpMethod Method => Path.Method;

/// <summary> Gets the path and query of the endpoint.</summary>
public string PathAndQuery => Path.PathAndQuery;

/// <summary> Represents an empty endpoint used as a default or placeholder instance of <see cref="Endpoint"/>. </summary>
public static Endpoint Empty(in EndpointPath path) => new(path, EmptyNode);

private static readonly Node EmptyNode = new(new Uri("http://empty.example"));
private readonly Node _node = Node;

/// <summary> Indicates whether the endpoint is an empty placeholder instance. </summary>
public bool IsEmpty => Node == EmptyNode;
/// <summary>
/// Represents a node within the transport layer of the Elastic search client.
/// This object encapsulates the characteristics of a node, allowing for comparisons and operations
/// within the broader search infrastructure.
/// </summary>
public Node Node
{
get => _node;
init
{
_node = value;
Uri = new(Node.Uri, Path.PathAndQuery);
}
}

/// <inheritdoc/>
public override string ToString() => $"{Path.Method.GetStringValue()} {Uri}";
Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Transport/Configuration/HeadersList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ private void AddToHeaders(HeadersList? headers)
/// </summary>
public int Count => _headers.Count;

// ReSharper disable once ConstantConditionalAccessQualifier
/// <inheritdoc />
public IEnumerator<string> GetEnumerator() => _headers.GetEnumerator();
public IEnumerator<string> GetEnumerator() => _headers?.GetEnumerator() ?? Enumerable.Empty<string>().GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand Down

0 comments on commit 2f0ebbc

Please sign in to comment.