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 @@ -61,5 +61,7 @@ internal static class Constants
internal const int CompatibilityLevel = 20; // Compatibility level for rules.

internal const string JsonNullValue = "null"; // String representation of null value in Json.

internal const string ContentTypeHeader = "Content-Type";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

using System;
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 NetHttpResponseMessage = System.Net.Http.HttpResponseMessage;

namespace Microsoft.WindowsAzure.ServiceLayer.Http
{
Expand Down Expand Up @@ -186,9 +188,37 @@ internal void SubmitTo(HttpRequestMessage request)

if (!string.IsNullOrEmpty(ContentType))
{
content.Headers.Add("Content-Type", ContentType);
content.Headers.Add(Constants.ContentTypeHeader, ContentType);
}
request.Content = content;
}

/// <summary>
/// Creates a content from the HTTP response.
/// </summary>
/// <param name="response">Source HTTP response.</param>
/// <returns>Content.</returns>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the period is unnecessary.

internal static HttpContent CreateFromResponse(NetHttpResponseMessage response)
{
Debug.Assert(response.IsSuccessStatusCode);
HttpContent content = null;

if (response.Content != null)
{
content = new HttpContent(new StreamContent(response.Content.ReadAsStreamAsync().Result));

IEnumerable<string> contentTypes;

if (response.Content.Headers.TryGetValues(Constants.ContentTypeHeader, out contentTypes))
{
foreach (string type in contentTypes)
{
content.ContentType = type;
break;
}
}
}
return content;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.ServiceLayer.Http;
using Windows.Foundation;
using Windows.Storage.Streams;

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

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
/// <summary>
Expand All @@ -42,7 +44,7 @@ public sealed class BrokeredMessageInfo
/// </summary>
public string ContentType
{
get { return _content.Headers.ContentType.ToString(); }
get { return _content.ContentType; }
}

/// <summary>
Expand Down Expand Up @@ -188,9 +190,7 @@ public string To
/// <returns>Content of the message.</returns>
public IAsyncOperation<string> ReadContentAsStringAsync()
{
return _content
.ReadAsStringAsync()
.AsAsyncOperation();
return _content.ReadAsStringAsync();
}

/// <summary>
Expand All @@ -199,10 +199,7 @@ public IAsyncOperation<string> ReadContentAsStringAsync()
/// <returns>Array of bytes.</returns>
public IAsyncOperation<IEnumerable<byte>> ReadContentAsBytesAsync()
{
return _content
.ReadAsByteArrayAsync()
.ContinueWith(t => (IEnumerable<byte>)t.Result, TaskContinuationOptions.OnlyOnRanToCompletion)
.AsAsyncOperation();
return _content.ReadAsByteArrayAsync();
}

/// <summary>
Expand All @@ -211,10 +208,7 @@ public IAsyncOperation<IEnumerable<byte>> ReadContentAsBytesAsync()
/// <returns>Stream.</returns>
public IAsyncOperation<IInputStream> ReadContentAsStreamAsync()
{
return _content
.ReadAsStreamAsync()
.ContinueWith(t => t.Result.AsInputStream(), TaskContinuationOptions.OnlyOnRanToCompletion)
.AsAsyncOperation();
return _content.ReadAsStreamAsync();
}

/// <summary>
Expand All @@ -228,9 +222,8 @@ public IAsyncInfo CopyContentToAsync(IOutputStream stream)
{
throw new ArgumentNullException("stream");
}
return _content
.CopyToAsync(stream.AsStreamForWrite())
.AsAsyncAction();

return _content.CopyToAsync(stream);
}

/// <summary>
Expand All @@ -239,9 +232,9 @@ public IAsyncInfo CopyContentToAsync(IOutputStream stream)
/// </summary>
/// <param name="response">Response with data.</param>
/// <returns></returns>
internal static BrokeredMessageInfo CreateFromPeekResponse(HttpResponseMessage response)
internal static BrokeredMessageInfo CreateFromPeekResponse(NetHttpResponseMessage response)
{
if (response.StatusCode == HttpStatusCode.NoContent || response.StatusCode == HttpStatusCode.ResetContent)
if (response.StatusCode == System.Net.HttpStatusCode.NoContent || response.StatusCode == System.Net.HttpStatusCode.ResetContent)
{
return null;
}
Expand All @@ -252,10 +245,10 @@ internal static BrokeredMessageInfo CreateFromPeekResponse(HttpResponseMessage r
/// Constructor. Initializes the object from the HTTP response.
/// </summary>
/// <param name="response">HTTP reponse with the data.</param>
internal BrokeredMessageInfo(HttpResponseMessage response)
internal BrokeredMessageInfo(NetHttpResponseMessage response)
{
Debug.Assert(response.IsSuccessStatusCode);
_content = response.Content;
_content = HttpContent.CreateFromResponse(response);
_customProperties = new CustomPropertiesDictionary(response);

DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Dictionary<string, object>));
Expand Down