Skip to content

Commit

Permalink
Update master from dev since we've published. (#300)
Browse files Browse the repository at this point in the history
* expose HttpProvider internal constructor with param HttpMessageHandle… (#289)

* expose HttpProvider internal constructor with param HttpMessageHandler to public
* Update HttpProviderTests.cs

* add unit tests

* Add Dispose method to RedirectHander and Xunit tests for RedirectHandler

* 1. Update RedirectHandler SendAsync method
2. Add RedriectHandlerTests for RedirectHandler in Microsoft.Graph.Core.Test with Mstest framework
3. Update RedirecthHandlerTests for RedirecthHandler in Microsoft.Graph.DotnetCore.Core.Test to test excpetioons thrown.

* 1. Update CopyRequest Method for setting content
1. Update IsRedirect Method to be more explicit
3. Update SendAsync for re-issue request
and removeAuth
4. Add tests for updates

* 1. change Dispose Method and typo in comments
2. remove ref

* remove ref

* remove NuGetPackageImportStamp

* disable PlannerTests

* move copy content into CopyRequest Method

* remove unnessary dispose and fix typo

* remove unused comments and fix tests issues.

* Generated new files that support the Security API, updates to the Intune API, Insights functionality on the user, MailTips, update to the subscription entity and additional documentation comments that will be used in the IntelliSense file. (#298)

* Updated copyright, version, and release notes. (#299)

* updated copyright per requirements
* Updated spec for build and packaging.
  • Loading branch information
MIchaelMainer authored Sep 20, 2018
1 parent 044880e commit 8fb11a7
Show file tree
Hide file tree
Showing 270 changed files with 13,549 additions and 449 deletions.
3 changes: 3 additions & 0 deletions Microsoft.Graph.sln
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ Global
{9F04608C-D845-4445-83B1-E6D4EEE38CBC} = {5E0B65FC-67B7-41F8-87BF-96D6A342C438}
{5169EDAD-1E05-42A5-A241-D6FA78A02C5C} = {6496B661-8321-4D07-ACC2-B6602649293C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0DB06E6E-58F0-497F-9ECC-00DD03BA9357}
EndGlobalSection
EndGlobal
19 changes: 10 additions & 9 deletions src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Microsoft Graph Core Client Library implements core functionality used by Microsoft Graph Client Libraries.</Description>
<Copyright>Copyright (c) Microsoft Corporation</Copyright>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<AssemblyTitle>Microsoft Graph Core Client Library</AssemblyTitle>
<VersionPrefix>1.10.0</VersionPrefix>
<FileVersion>1.10.0</FileVersion>
<AssemblyVersion>1.10.0</AssemblyVersion>
<VersionPrefix>1.11.0</VersionPrefix>
<FileVersion>1.11.0</FileVersion>
<AssemblyVersion>1.11.0</AssemblyVersion>
<Authors>Microsoft</Authors>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<PreserveCompilationContext>false</PreserveCompilationContext>
<AssemblyName>Microsoft.Graph.Core</AssemblyName>
<PackageId>Microsoft.Graph.Core</PackageId>
<PackageTags>Microsoft Office365;Graph;GraphServiceClient;Outlook;OneDrive;AzureAD;GraphAPI;Productivity;SharePoint;Intune;SDK</PackageTags>
<PackageReleaseNotes>
July 2018 Release Summary (version 1.10.0)
September 2018 Release Summary (version 1.11.0)

New features
- Added the ability to append an arbitrary URL segment to a request. This will support the creation of custom requests.
- Set signing properties in .csproj to be 'false' by default.
- exposed the HttpProvider constructor
</PackageReleaseNotes>
<PackageProjectUrl>https://developer.microsoft.com/graph</PackageProjectUrl>
<PackageLicenseUrl>http://aka.ms/devservicesagreement</PackageLicenseUrl>
Expand All @@ -37,7 +35,7 @@ New features
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.10.0</Version>
<Version>1.11.0</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.1|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.1\Microsoft.Graph.Core.xml</DocumentationFile>
Expand All @@ -61,4 +59,7 @@ New features
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
<PackageReference Include="Newtonsoft.Json" Version="[9.0.1,12)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Microsoft.Graph.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.10.0")]
[assembly: AssemblyFileVersion("1.10.0.0")]
[assembly: AssemblyVersion("1.11.0")]
[assembly: AssemblyFileVersion("1.11.0.0")]

#if DEBUG
[assembly: InternalsVisibleTo("Microsoft.Graph.Core.Test")]
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Graph.Core/Requests/HttpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public HttpProvider(HttpClientHandler httpClientHandler, bool disposeHandler, IS
/// <param name="httpMessageHandler">An HTTP message handler to pass to the <see cref="HttpClient"/> for sending requests.</param>
/// <param name="disposeHandler">Whether or not to dispose the client handler on Dispose().</param>
/// <param name="serializer">A serializer for serializing and deserializing JSON objects.</param>
internal HttpProvider(HttpMessageHandler httpMessageHandler, bool disposeHandler, ISerializer serializer)
public HttpProvider(HttpMessageHandler httpMessageHandler, bool disposeHandler, ISerializer serializer)
{
this.disposeHandler = disposeHandler;
this.httpMessageHandler = httpMessageHandler ?? new HttpClientHandler { AllowAutoRedirect = false };
Expand Down
151 changes: 151 additions & 0 deletions src/Microsoft.Graph.Core/Requests/RedirectHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

namespace Microsoft.Graph
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using System.IO;

/// <summary>
/// An <see cref="DelegatingHandler"/> implementation using standard .NET libraries.
/// </summary>
public class RedirectHandler : DelegatingHandler
{

private const int maxRedirects = 5;

/// <summary>
/// Constructs a new <see cref="RedirectHandler"/>
/// </summary>
/// <param name="innerHandler">An HTTP message handler to pass to the <see cref="HttpMessageHandler"/> for sending requests.</param>
public RedirectHandler(HttpMessageHandler innerHandler)
{
InnerHandler = innerHandler;
}


/// <summary>
/// Sends the Request
/// </summary>
/// <param name="request">The <see cref="HttpRequestMessage"/> to send.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>for the request.</param>
/// <returns>The <see cref="HttpResponseMessage"/>.</returns>
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{

// send request first time to get response
var response = await base.SendAsync(request, cancellationToken);

// check response status code
if (IsRedirect(response.StatusCode))
{

var redirectCount = 0;

while (redirectCount < maxRedirects)
{
// general copy request with internal CopyRequest(see copyRequest for details) method
var newRequest = await CopyRequest(response.RequestMessage);

// status code == 303: change request method from post to get and content to be null
if (response.StatusCode == HttpStatusCode.SeeOther)
{
newRequest.Content = null;
newRequest.Method = HttpMethod.Get;
}

// Set newRequestUri from response
newRequest.RequestUri = response.Headers.Location;

// Remove Auth if http request's scheme or host changes
if (String.Compare(newRequest.RequestUri.Host, request.RequestUri.Host, StringComparison.OrdinalIgnoreCase) != 0 ||
!newRequest.RequestUri.Scheme.Equals(request.RequestUri.Scheme))
{
newRequest.Headers.Authorization = null;
}

// Send redirect request to get reponse
response = await base.SendAsync(newRequest, cancellationToken);

// Check response status code
if (!IsRedirect(response.StatusCode))
{
return response;
}
redirectCount++;
}
throw new ServiceException(
new Error
{
Code = ErrorConstants.Codes.TooManyRedirects,
Message = string.Format(ErrorConstants.Messages.TooManyRedirectsFormatString, redirectCount)
});

}
return response;

}

/// <summary>
/// Create a new HTTP request by copying previous HTTP request's headers and properties from response's request message.
/// </summary>
/// <param name="originalRequest">The previous <see cref="HttpRequestMessage"/> needs to be copy.</param>
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
/// <remarks>
/// Re-issue a new HTTP request with the previous request's headers and properities
/// </remarks>
internal async Task<HttpRequestMessage> CopyRequest(HttpRequestMessage originalRequest)
{
var newRequest = new HttpRequestMessage(originalRequest.Method, originalRequest.RequestUri);

foreach (var header in originalRequest.Headers)
{
newRequest.Headers.TryAddWithoutValidation(header.Key, header.Value);
}

foreach (var property in originalRequest.Properties)
{
newRequest.Properties.Add(property);
}

// Set Content if previous request contains
if (originalRequest.Content != null && originalRequest.Content.Headers.ContentLength != 0)
{
newRequest.Content = new StreamContent(await originalRequest.Content.ReadAsStreamAsync());
}

return newRequest;
}


/// <summary>
/// Checks whether <see cref="HttpStatusCode"/> is redirected
/// </summary>
/// <param name="statusCode">The <see cref="HttpStatusCode"/>.</param>
/// <returns>Bool value for redirection or not</returns>
private bool IsRedirect(HttpStatusCode statusCode)
{
if (statusCode == HttpStatusCode.MovedPermanently ||
statusCode == HttpStatusCode.Found ||
statusCode == HttpStatusCode.SeeOther ||
statusCode == HttpStatusCode.TemporaryRedirect ||
statusCode == (HttpStatusCode)308
)
{
return true;
}
return false;
}


}

}
21 changes: 12 additions & 9 deletions src/Microsoft.Graph/Microsoft.Graph.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Microsoft Graph Client Library allows you to call Office 365, Azure AD and other Microsoft services through a single unified developer experience.</Description>
<Copyright>Copyright (c) Microsoft Corporation</Copyright>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<AssemblyTitle>Microsoft Graph Client Library</AssemblyTitle>
<VersionPrefix>1.10.0</VersionPrefix>
<FileVersion>1.10.0</FileVersion>
<AssemblyVersion>1.10.0</AssemblyVersion>
<VersionPrefix>1.11.0</VersionPrefix>
<FileVersion>1.11.0</FileVersion>
<AssemblyVersion>1.11.0</AssemblyVersion>
<Authors>Microsoft</Authors>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<PreserveCompilationContext>false</PreserveCompilationContext>
<AssemblyName>Microsoft.Graph</AssemblyName>
<PackageId>Microsoft.Graph</PackageId>
<PackageTags>Microsoft Office365;Graph;GraphServiceClient;Outlook;OneDrive;AzureAD;GraphAPI;Productivity;SharePoint;Intune;SDK</PackageTags>
<PackageReleaseNotes>
July 2018 Release Summary (version 1.10.0)
September 2018 Release Summary (version 1.11.0)

- Updated reference to System.Net.Http to address a vulnerability and issue with .Net &gt;=4.7.2.
- Set signing properties in .csproj to be 'false' by default.
- Added custom request builders that help add user activity and history.
- Support the new Security Alerts API
- Updates to the Intune API
- Insights functionality updated for the user entity
- MailTips are now enabled
- Update to the subscription entity and additional documentation comments propagated to the IntelliSense file.
- EducationClass entities now support adding reference navigation to the teachers and members entity collections.
</PackageReleaseNotes>
<PackageProjectUrl>https://developer.microsoft.com/graph</PackageProjectUrl>
<PackageLicenseUrl>http://aka.ms/devservicesagreement</PackageLicenseUrl>
Expand All @@ -37,7 +40,7 @@ July 2018 Release Summary (version 1.10.0)
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.10.0</Version>
<Version>1.11.0</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.1|AnyCPU'">
<DocumentationFile>bin\Release\Microsoft.Graph.xml</DocumentationFile>
Expand Down
Loading

0 comments on commit 8fb11a7

Please sign in to comment.