Skip to content

Commit

Permalink
Make PipelineRequest.Uri nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
annelo-msft committed Feb 15, 2024
1 parent 6a60669 commit 1d12717
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 30 deletions.
4 changes: 2 additions & 2 deletions sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ protected PipelineRequest() { }
protected abstract System.ClientModel.Primitives.PipelineRequestHeaders HeadersCore { get; }
public string Method { get { throw null; } set { } }
protected abstract string MethodCore { get; set; }
public System.Uri Uri { get { throw null; } set { } }
protected abstract System.Uri UriCore { get; set; }
public System.Uri? Uri { get { throw null; } set { } }
protected abstract System.Uri? UriCore { get; set; }
public abstract void Dispose();
}
public abstract partial class PipelineRequestHeaders : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>, System.Collections.IEnumerable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ protected PipelineRequest() { }
protected abstract System.ClientModel.Primitives.PipelineRequestHeaders HeadersCore { get; }
public string Method { get { throw null; } set { } }
protected abstract string MethodCore { get; set; }
public System.Uri Uri { get { throw null; } set { } }
protected abstract System.Uri UriCore { get; set; }
public System.Uri? Uri { get { throw null; } set { } }
protected abstract System.Uri? UriCore { get; set; }
public abstract void Dispose();
}
public abstract partial class PipelineRequestHeaders : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>, System.Collections.IEnumerable
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/System.ClientModel/src/Message/PipelineRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public string Method

protected abstract string MethodCore { get; set; }

public Uri Uri
public Uri? Uri
{
get => UriCore;
set => UriCore = value;
}

protected abstract Uri UriCore { get; set; }
protected abstract Uri? UriCore { get; set; }

public PipelineRequestHeaders Headers => HeadersCore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,9 @@ protected override string MethodCore
}
}

protected override Uri UriCore
protected override Uri? UriCore
{
get
{
if (_uri is null)
{
throw new InvalidOperationException("Uri has not been set on this instance.");
}

return _uri;
}
get => _uri;
set
{
Argument.AssertNotNull(value, nameof(value));
Expand Down Expand Up @@ -89,6 +81,11 @@ private static HttpMethod ToHttpMethod(string method)

internal static HttpRequestMessage BuildHttpRequestMessage(PipelineRequest request, CancellationToken cancellationToken)
{
if (request.Uri is null)
{
throw new InvalidOperationException("Uri must be set on message request prior to sending message.");
}

HttpMethod method = ToHttpMethod(request.Method);
Uri uri = request.Uri;
HttpRequestMessage httpRequest = new HttpRequestMessage(method, uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,9 @@ protected override string MethodCore
set => _method = value;
}

protected override Uri UriCore
protected override Uri? UriCore
{
get
{
if (_uri is null)
{
throw new InvalidOperationException("Uri has not be set on HttpMessageRequest instance.");
}

return _uri;
}

get => _uri;
set => _uri = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void SetResponse(int status)

private class TransportRequest : PipelineRequest
{
private Uri _uri;
private Uri? _uri;
private readonly PipelineRequestHeaders _headers;

public TransportRequest()
Expand All @@ -145,7 +145,7 @@ protected override string MethodCore
set => throw new NotImplementedException();
}

protected override Uri UriCore
protected override Uri? UriCore
{
get => _uri;
set => _uri = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected override string MethodCore
set => throw new NotImplementedException();
}

protected override Uri UriCore
protected override Uri? UriCore
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
Expand Down

0 comments on commit 1d12717

Please sign in to comment.