Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage.Streams;

using NetHttpContent = System.Net.Http.HttpContent;
using NetHttpRequestMessage = System.Net.Http.HttpRequestMessage;
using NetHttpResponseMessage = System.Net.Http.HttpResponseMessage;

namespace Microsoft.WindowsAzure.ServiceLayer.Http
Expand Down Expand Up @@ -181,7 +181,7 @@ public IAsyncAction CopyToBufferAsync()
/// Submits content data into the given request.
/// </summary>
/// <param name="request">Target request.</param>
internal void SubmitTo(HttpRequestMessage request)
internal void SubmitTo(NetHttpRequestMessage request)
{
NetHttpContent content = new System.Net.Http.StreamContent(
_rawContent.ReadAsStreamAsync().Result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright 2012 Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.WindowsAzure.ServiceLayer.Http
{
/// <summary>
/// Lists HTTP methods used by pipeline implementation.
/// </summary>
internal static class HttpMethod
{
internal const string Post = "POST";
internal const string Get = "GET";
internal const string Put = "PUT";
internal const string Delete = "DELETE";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// Copyright 2012 Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using NetHttpMethod = System.Net.Http.HttpMethod;
using NetHttpRequestMessage = System.Net.Http.HttpRequestMessage;

namespace Microsoft.WindowsAzure.ServiceLayer.Http
{
/// <summary>
/// Represents an HTTP request.
/// </summary>
public sealed class HttpRequest
{
private NetHttpMethod _method; // HTTP method verb (get/put/post, etc.)

/// <summary>
/// Gets the URI used for the HTTP request.
/// </summary>
public Uri Uri { get; private set; }

/// <summary>
/// Gets the HTTP method used for HTTP request.
/// </summary>
public string Method
{
get { return _method.ToString(); }
}

/// <summary>
/// Gets the headers.
/// </summary>
public IDictionary<string, string> Headers { get; private set; }

/// <summary>
/// Gets the content of the request.
/// </summary>
public HttpContent Content { get; set; }

/// <summary>
/// Initializes the request.
/// </summary>
/// <param name="method">The request's HTTP method.</param>
/// <param name="uri">The request's URI.</param>
public HttpRequest(string method, Uri uri)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
if (method == null)
{
throw new ArgumentNullException("method");
}

Uri = uri;
_method = new NetHttpMethod(method);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better variable naming other than method ? seems confusing with _method ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is that confusing. The scope of the "method" variable is limited to the constructor which is ~10 lines long; it's hard to get confused here.

Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Creates a .Net request and populates it with all data.
/// </summary>
/// <returns>.Net request.</returns>
internal NetHttpRequestMessage CreateNetRequest()
{
NetHttpRequestMessage request = new NetHttpRequestMessage(_method, Uri);

// Populate headers.
foreach (KeyValuePair<string, string> headerItem in Headers)
{
request.Headers.Add(headerItem.Key, headerItem.Value);
}

// Populate content.
if (Content != null)
{
Content.SubmitTo(request);
}
return request;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it have a new line inbetween the closing bracket and the return statement ? Usually R# advises for it and i kinda like it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strict preference for empy lines inside a body of a methods, however, I prefer to avoid having too many empty lines in the code because it blows up the document and reduces the amount of useful information that fits into a single screen. I don't think that an empty line here affects readability of the code in any way, so I'd prefer to keep it as is.

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Http\HttpContent.cs" />
<Compile Include="Http\HttpMethod.cs" />
<Compile Include="Http\HttpRequest.cs" />
<Compile Include="Http\IHttpContent.cs" />
<Compile Include="Http\MemoryContent.cs" />
<Compile Include="Http\StreamContent.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
using System;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using Microsoft.WindowsAzure.ServiceLayer.Http;

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
Expand Down Expand Up @@ -266,7 +266,7 @@ private static string DateTimeToUtcString(DateTimeOffset? source)
/// Submits content of the class to the given HTTP request.
/// </summary>
/// <param name="request">Target request.</param>
internal void SubmitTo(HttpRequestMessage request)
internal void SubmitTo(HttpRequest request)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(BrokerProperties));
using (MemoryStream stream = new MemoryStream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using Windows.Foundation;
using Windows.Storage.Streams;

using NetHttpContent = System.Net.Http.HttpContent;
using NetHttpResponseMessage = System.Net.Http.HttpResponseMessage;

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
using Windows.Foundation.Metadata;
using Windows.Storage.Streams;

using NetHttpContent = System.Net.Http.HttpContent;
using NetHttpRequestMessage = System.Net.Http.HttpRequestMessage;

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
/// <summary>
Expand Down Expand Up @@ -206,16 +203,15 @@ public static BrokeredMessageSettings CreateFromStream(IInputStream stream)
return new BrokeredMessageSettings(content);
}


/// <summary>
/// Submits content to the given request.
/// </summary>
/// <param name="request">Target request.</param>
internal void SubmitTo(NetHttpRequestMessage request)
internal void SubmitTo(HttpRequest request)
{
_brokerProperties.SubmitTo(request);
_customProperties.SubmitTo(request);
Content.SubmitTo(request);
request.Content = Content;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
using System.Globalization;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.ServiceLayer.Http;
using Windows.Data.Json;

using NetHttpResponseMessage = System.Net.Http.HttpResponseMessage;

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
/// <summary>
Expand All @@ -42,7 +44,7 @@ internal CustomPropertiesDictionary()
/// Initializes a dictionary with properties from the response.
/// </summary>
/// <param name="response">Response.</param>
internal CustomPropertiesDictionary(HttpResponseMessage response)
internal CustomPropertiesDictionary(NetHttpResponseMessage response)
: this()
{
foreach (KeyValuePair<string, IEnumerable<string>> item in response.Headers)
Expand All @@ -66,7 +68,7 @@ internal CustomPropertiesDictionary(HttpResponseMessage response)
/// Submits stored properties to the request.
/// </summary>
/// <param name="request">HTTP request.</param>
internal void SubmitTo(HttpRequestMessage request)
internal void SubmitTo(HttpRequest request)
{
foreach (KeyValuePair<string, object> item in this)
{
Expand Down Expand Up @@ -107,7 +109,6 @@ private static object DecodeValue(JsonValue value)
return dateTime.ToUniversalTime();
}
return stringValue;

}

/// <summary>
Expand Down
Loading