├── .gitignore ├── LICENSE ├── System.Net.Http ├── .nuget │ ├── NuGet.Config │ └── NuGet.exe ├── Assembly │ └── AssemblyInfo.cs ├── Documentation │ └── en │ │ ├── System.Net.Http.Headers │ │ ├── AuthenticationHeaderValue.xml │ │ ├── CacheControlHeaderValue.xml │ │ ├── ContentDispositionHeaderValue.xml │ │ ├── ContentRangeHeaderValue.xml │ │ ├── EntityTagHeaderValue.xml │ │ ├── HttpContentHeaders.xml │ │ ├── HttpHeaderValueCollection`1.xml │ │ ├── HttpHeaders.xml │ │ ├── HttpRequestHeaders.xml │ │ ├── HttpResponseHeaders.xml │ │ ├── MediaTypeHeaderValue.xml │ │ ├── MediaTypeWithQualityHeaderValue.xml │ │ ├── NameValueHeaderValue.xml │ │ ├── NameValueWithParametersHeaderValue.xml │ │ ├── ProductHeaderValue.xml │ │ ├── ProductInfoHeaderValue.xml │ │ ├── RangeConditionHeaderValue.xml │ │ ├── RangeHeaderValue.xml │ │ ├── RangeItemHeaderValue.xml │ │ ├── RetryConditionHeaderValue.xml │ │ ├── StringWithQualityHeaderValue.xml │ │ ├── TransferCodingHeaderValue.xml │ │ ├── TransferCodingWithQualityHeaderValue.xml │ │ ├── ViaHeaderValue.xml │ │ └── WarningHeaderValue.xml │ │ ├── System.Net.Http │ │ ├── ByteArrayContent.xml │ │ ├── CFNetworkHandler.xml │ │ ├── ClientCertificateOption.xml │ │ ├── DelegatingHandler.xml │ │ ├── FormUrlEncodedContent.xml │ │ ├── HttpClient.xml │ │ ├── HttpClientHandler.xml │ │ ├── HttpCompletionOption.xml │ │ ├── HttpContent.xml │ │ ├── HttpMessageHandler.xml │ │ ├── HttpMessageInvoker.xml │ │ ├── HttpMethod.xml │ │ ├── HttpRequestException.xml │ │ ├── HttpRequestMessage.xml │ │ ├── HttpResponseMessage.xml │ │ ├── MessageProcessingHandler.xml │ │ ├── MultipartContent.xml │ │ ├── MultipartFormDataContent.xml │ │ ├── StreamContent.xml │ │ └── StringContent.xml │ │ ├── index.xml │ │ ├── ns-System.Net.Http.Headers.xml │ │ └── ns-System.Net.Http.xml ├── Makefile ├── Rackspace.HttpClient35.nuspec ├── System.Net.Http-net_4_5.csproj ├── System.Net.Http-net_4_5.sln ├── System.Net.Http-tests-net_4_5.csproj ├── System.Net.Http.Headers │ ├── AuthenticationHeaderValue.cs │ ├── CacheControlHeaderValue.cs │ ├── CollectionExtensions.cs │ ├── CollectionParser.cs │ ├── ContentDispositionHeaderValue.cs │ ├── ContentRangeHeaderValue.cs │ ├── EntityTagHeaderValue.cs │ ├── HashCodeCalculator.cs │ ├── HeaderInfo.cs │ ├── HttpContentHeaders.cs │ ├── HttpHeaderKind.cs │ ├── HttpHeaderValueCollection.cs │ ├── HttpHeaders.cs │ ├── HttpRequestHeaders.cs │ ├── HttpResponseHeaders.cs │ ├── Lexer.cs │ ├── MediaTypeHeaderValue.cs │ ├── MediaTypeWithQualityHeaderValue.cs │ ├── NameValueHeaderValue.cs │ ├── NameValueWithParametersHeaderValue.cs │ ├── Parser.cs │ ├── ProductHeaderValue.cs │ ├── ProductInfoHeaderValue.cs │ ├── QualityValue.cs │ ├── RangeConditionHeaderValue.cs │ ├── RangeHeaderValue.cs │ ├── RangeItemHeaderValue.cs │ ├── RetryConditionHeaderValue.cs │ ├── StringWithQualityHeaderValue.cs │ ├── TransferCodingHeaderValue.cs │ ├── TransferCodingWithQualityHeaderValue.cs │ ├── ViaHeaderValue.cs │ └── WarningHeaderValue.cs ├── System.Net.Http.dll.sources ├── System.Net.Http │ ├── ByteArrayContent.cs │ ├── ClientCertificateOption.cs │ ├── DelegatingHandler.cs │ ├── FormUrlEncodedContent.cs │ ├── HttpClient.cs │ ├── HttpClientHandler.cs │ ├── HttpCompletionOption.cs │ ├── HttpContent.cs │ ├── HttpMessageHandler.cs │ ├── HttpMessageInvoker.cs │ ├── HttpMethod.cs │ ├── HttpRequestException.cs │ ├── HttpRequestMessage.cs │ ├── HttpResponseMessage.cs │ ├── MessageProcessingHandler.cs │ ├── MultipartContent.cs │ ├── MultipartFormDataContent.cs │ ├── StreamContent.cs │ ├── StringContent.cs │ └── StringEx.cs ├── System.Net.Http_test.dll.sources ├── Test │ ├── System.Net.Http.Headers │ │ ├── AuthenticationHeaderValueTest.cs │ │ ├── CacheControlHeaderValueTest.cs │ │ ├── ContentDispositionHeaderValueTest.cs │ │ ├── ContentRangeHeaderValueTest.cs │ │ ├── EntityTagHeaderValueTest.cs │ │ ├── HttpHeaderValueCollection.cs │ │ ├── HttpHeadersTest.cs │ │ ├── MediaTypeHeaderValueTest.cs │ │ ├── MediaTypeWithQualityHeaderValueTest.cs │ │ ├── NameValueHeaderValueTest.cs │ │ ├── NameValueWithParametersHeaderValueTest.cs │ │ ├── ProductHeaderValueTest.cs │ │ ├── ProductInfoHeaderValueTest.cs │ │ ├── RangeConditionHeaderValueTest.cs │ │ ├── RangeHeaderValueTest.cs │ │ ├── RangeItemHeaderValueTest.cs │ │ ├── RetryConditionHeaderValueTest.cs │ │ ├── StringWithQualityHeaderValueTest.cs │ │ ├── TransferCodingHeaderValueTest.cs │ │ ├── TransferCodingWithQualityHeaderValueTest.cs │ │ ├── ViaHeaderValueTest.cs │ │ └── WarningHeaderValueTest.cs │ └── System.Net.Http │ │ ├── ByteArrayContentTest.cs │ │ ├── DelegatingHandlerTest.cs │ │ ├── FormUrlEncodedContentTest.cs │ │ ├── HttpClientHandlerTest.cs │ │ ├── HttpClientTest.cs │ │ ├── HttpMethodTest.cs │ │ ├── HttpRequestMessageTest.cs │ │ ├── HttpResponseMessageTest.cs │ │ ├── MultipartContentTest.cs │ │ ├── MultipartFormDataContentTest.cs │ │ ├── StreamContentTest.cs │ │ └── StringContentTest.cs ├── monotouch_System.Net.Http.dll.sources ├── packages.System.Net.Http-net_4_5.config └── packages.System.Net.Http-tests-net_4_5.config └── build ├── KeyReporting.targets ├── build.ps1 ├── check-key.ps1 ├── common └── Consts.cs ├── keys.ps1 ├── keys ├── HttpClient35.dev.snk └── HttpClient35.snk ├── push.ps1 └── version.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | # Build folders 2 | obj/ 3 | bin/ 4 | packages/ 5 | build/nuget/ 6 | 7 | # Per-user files for Visual Studio 8 | *.suo 9 | *.csproj.user 10 | 11 | # Roslyn IntelliSense Cache 12 | *.sln.ide/ 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001, 2002, 2003 Ximian, Inc and the individuals listed 2 | on the ChangeLog entries. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /System.Net.Http/.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /System.Net.Http/.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-httpclient35/9ab946aebe82cf57b8d36906e7f47305afab99fe/System.Net.Http/.nuget/NuGet.exe -------------------------------------------------------------------------------- /System.Net.Http/Assembly/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // AssemblyInfo.cs 3 | // 4 | // Authors: 5 | // Marek Safar (marek.safar@gmail.com) 6 | // 7 | // Copyright 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Reflection; 31 | using System.Resources; 32 | using System.Security; 33 | using System.Security.Permissions; 34 | using System.Diagnostics; 35 | using System.Runtime.CompilerServices; 36 | using System.Runtime.InteropServices; 37 | 38 | // General Information about the assembly 39 | 40 | [assembly: AssemblyTitle ("System.Net.Http.dll")] 41 | [assembly: AssemblyDescription ("System.Net.Http.dll")] 42 | [assembly: AssemblyDefaultAlias ("System.Net.Http.dll")] 43 | 44 | [assembly: AssemblyCompany (Consts.MonoCompany)] 45 | [assembly: AssemblyProduct (Consts.MonoProduct)] 46 | [assembly: AssemblyCopyright (Consts.MonoCopyright)] 47 | 48 | #if MOBILE 49 | [assembly: AssemblyVersion ("4.0.0.0")] 50 | [assembly: SatelliteContractVersion ("4.0.0.0")] 51 | [assembly: AssemblyInformationalVersion ("4.0.50524.0")] 52 | [assembly: AssemblyFileVersion ("4.0.50524.0")] 53 | #else 54 | [assembly: AssemblyVersion (Consts.FxVersion)] 55 | [assembly: SatelliteContractVersion (Consts.FxVersion)] 56 | [assembly: AssemblyInformationalVersion (Consts.FxFileVersion + Consts.FxInformationalSuffix)] 57 | [assembly: AssemblyFileVersion (Consts.FxFileVersion)] 58 | #endif 59 | 60 | [assembly: NeutralResourcesLanguage ("en-US")] 61 | [assembly: CLSCompliant (true)] 62 | 63 | [assembly: ComVisible (false)] 64 | -------------------------------------------------------------------------------- /System.Net.Http/Documentation/en/System.Net.Http/ClientCertificateOption.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | System.Net.Http 7 | 4.0.0.0 8 | 9 | 10 | System.Enum 11 | 12 | 13 | To be added. 14 | 15 | 16 | Specifies how client certificates are provided. 17 | 18 | 19 | 20 | 21 | 22 | 23 | Field 24 | 25 | 4.0.0.0 26 | 27 | 28 | System.Net.Http.ClientCertificateOption 29 | 30 | 31 | 32 | 33 | The will attempt to provide all available client certificates automatically. 34 | 35 | 36 | 37 | 38 | 39 | 40 | Field 41 | 42 | 4.0.0.0 43 | 44 | 45 | System.Net.Http.ClientCertificateOption 46 | 47 | 48 | 49 | 50 | The application manually provides the client certificates to the . This value is the default. 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /System.Net.Http/Documentation/en/System.Net.Http/FormUrlEncodedContent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | System.Net.Http 7 | 4.0.0.0 8 | 9 | 10 | System.Net.Http.ByteArrayContent 11 | 12 | 13 | 14 | To be added. 15 | 16 | 17 | A container for name/value tuples encoded using application/x-www-form-urlencoded MIME type. 18 | 19 | 20 | 21 | 22 | 23 | 24 | Constructor 25 | 26 | 4.0.0.0 27 | 28 | 29 | 30 | 31 | 32 | To be added. 33 | 34 | 35 | Initializes a new instance of the class with a specific collection of name/value pairs. 36 | 37 | 38 | A collection of name/value pairs. 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /System.Net.Http/Documentation/en/System.Net.Http/HttpCompletionOption.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | System.Net.Http 7 | 4.0.0.0 8 | 9 | 10 | System.Enum 11 | 12 | 13 | To be added. 14 | 15 | 16 | Indicates if operations should be considered completed either as soon as a response is available, or after reading the entire response message including the content. 17 | 18 | 19 | 20 | 21 | 22 | 23 | Field 24 | 25 | 4.0.0.0 26 | 27 | 28 | System.Net.Http.HttpCompletionOption 29 | 30 | 31 | 32 | 33 | The operation should complete after reading the entire response including the content. 34 | 35 | 36 | 37 | 38 | 39 | 40 | Field 41 | 42 | 4.0.0.0 43 | 44 | 45 | System.Net.Http.HttpCompletionOption 46 | 47 | 48 | 49 | 50 | The operation should complete as soon as a response is available and headers are read. The content is not read yet. 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /System.Net.Http/Documentation/en/System.Net.Http/HttpRequestException.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | System.Net.Http 7 | 4.0.0.0 8 | 9 | 10 | System.Exception 11 | 12 | 13 | 14 | To be added. 15 | 16 | 17 | A base class for exceptions thrown by the and classes. 18 | 19 | 20 | 21 | 22 | 23 | 24 | Constructor 25 | 26 | 4.0.0.0 27 | 28 | 29 | 30 | To be added. 31 | 32 | 33 | Initializes a new instance of the class. 34 | 35 | 36 | 37 | 38 | 39 | 40 | Constructor 41 | 42 | 4.0.0.0 43 | 44 | 45 | 46 | 47 | 48 | To be added. 49 | 50 | 51 | Initializes a new instance of the class with a specific message that describes the current exception. 52 | 53 | 54 | A message that describes the current exception. 55 | 56 | 57 | 58 | 59 | 60 | Constructor 61 | 62 | 4.0.0.0 63 | 64 | 65 | 66 | 67 | 68 | 69 | To be added. 70 | 71 | 72 | Initializes a new instance of the class with a specific message that describes the current exception and an inner exception. 73 | 74 | 75 | A message that describes the current exception. 76 | 77 | The inner exception. 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /System.Net.Http/Documentation/en/System.Net.Http/StringContent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | System.Net.Http 7 | 4.0.0.0 8 | 9 | 10 | System.Net.Http.ByteArrayContent 11 | 12 | 13 | 14 | To be added. 15 | 16 | 17 | Provides HTTP content based on a string. 18 | 19 | 20 | 21 | 22 | 23 | 24 | Constructor 25 | 26 | 4.0.0.0 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | The media type for the created defaults to text/plain. 35 | 36 | 37 | 38 | Creates a new instance of the class. 39 | 40 | 41 | The content used to initialize the . 42 | 43 | 44 | 45 | 46 | 47 | Constructor 48 | 49 | 4.0.0.0 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | The media type for the created defaults to text/plain. 59 | 60 | 61 | 62 | Creates a new instance of the class. 63 | 64 | 65 | The content used to initialize the . 66 | 67 | The encoding to use for the content. 68 | 69 | 70 | 71 | 72 | 73 | Constructor 74 | 75 | 4.0.0.0 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | To be added. 84 | 85 | 86 | Creates a new instance of the class. 87 | 88 | 89 | The content used to initialize the . 90 | 91 | The encoding to use for the content. 92 | 93 | The media type to use for the content. 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /System.Net.Http/Documentation/en/ns-System.Net.Http.Headers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Provides support for collections of HTTP headers used by the namespace 7 | 8 | 9 | 10 | The namespace provides support for HTTP headers as defined in RFC 2616 by the IETF. 11 | 12 | 13 | -------------------------------------------------------------------------------- /System.Net.Http/Makefile: -------------------------------------------------------------------------------- 1 | thisdir = class/System.Net.Http 2 | SUBDIRS = 3 | include ../../build/rules.make 4 | 5 | LIBRARY = System.Net.Http.dll 6 | 7 | LIB_MCS_FLAGS = -r:System.Core.dll -r:System.dll $(EXTRA_LIB_MCS_FLAGS) 8 | 9 | TEST_MCS_FLAGS = -r:System.dll -r:System.Core.dll 10 | 11 | include ../../build/library.make 12 | -------------------------------------------------------------------------------- /System.Net.Http/Rackspace.HttpClient35.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Rackspace.HttpClient35 5 | 0.0.0 6 | System.Net.Http for .NET 3.5 7 | Sam Harwell 8 | Sam Harwell 9 | https://raw.github.com/rackerlabs/dotnet-httpclient35/v$version$/LICENSE 10 | https://github.com/rackerlabs/dotnet-httpclient35 11 | true 12 | A port of Mono's implementation of the complete System.Net.Http assembly to .NET 3.5. 13 | https://github.com/rackerlabs/dotnet-httpclient35/releases/v$version$ 14 | 15 | httpclient 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http-net_4_5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http-net_4_5", "System.Net.Http-net_4_5.csproj", "{9862694D-E4FA-418B-8692-A0280FEDDF36}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http-tests-net_4_5", "System.Net.Http-tests-net_4_5.csproj", "{155AEF28-C81F-405D-9072-9D52780E3E70}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{FBC69AB7-1404-44B6-9C7B-AC19901A6D8B}" 11 | ProjectSection(SolutionItems) = preProject 12 | .nuget\NuGet.Config = .nuget\NuGet.Config 13 | .nuget\NuGet.exe = .nuget\NuGet.exe 14 | EndProjectSection 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{6FD18814-E49B-4621-8884-B80215B244DB}" 17 | ProjectSection(SolutionItems) = preProject 18 | ..\build\build.ps1 = ..\build\build.ps1 19 | ..\build\check-key.ps1 = ..\build\check-key.ps1 20 | ..\build\keys.ps1 = ..\build\keys.ps1 21 | ..\build\push.ps1 = ..\build\push.ps1 22 | ..\build\version.ps1 = ..\build\version.ps1 23 | EndProjectSection 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Release|Any CPU = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {9862694D-E4FA-418B-8692-A0280FEDDF36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {9862694D-E4FA-418B-8692-A0280FEDDF36}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {9862694D-E4FA-418B-8692-A0280FEDDF36}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {9862694D-E4FA-418B-8692-A0280FEDDF36}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {155AEF28-C81F-405D-9072-9D52780E3E70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {155AEF28-C81F-405D-9072-9D52780E3E70}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {155AEF28-C81F-405D-9072-9D52780E3E70}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {155AEF28-C81F-405D-9072-9D52780E3E70}.Release|Any CPU.Build.0 = Release|Any CPU 39 | EndGlobalSection 40 | GlobalSection(SolutionProperties) = preSolution 41 | HideSolutionNode = FALSE 42 | EndGlobalSection 43 | GlobalSection(MonoDevelopProperties) = preSolution 44 | StartupItem = System.Net.Http-net_4_5.csproj 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/AuthenticationHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // AuthenticationHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class AuthenticationHeaderValue : ICloneable 34 | { 35 | public AuthenticationHeaderValue (string scheme) 36 | : this (scheme, null) 37 | { 38 | } 39 | 40 | public AuthenticationHeaderValue (string scheme, string parameter) 41 | { 42 | Parser.Token.Check (scheme); 43 | 44 | this.Scheme = scheme; 45 | this.Parameter = parameter; 46 | } 47 | 48 | private AuthenticationHeaderValue () 49 | { 50 | } 51 | 52 | public string Parameter { get; private set; } 53 | public string Scheme { get; private set; } 54 | 55 | object ICloneable.Clone () 56 | { 57 | return MemberwiseClone (); 58 | } 59 | 60 | public override bool Equals (object obj) 61 | { 62 | var source = obj as AuthenticationHeaderValue; 63 | return source != null && 64 | string.Equals (source.Scheme, Scheme, StringComparison.OrdinalIgnoreCase) && 65 | source.Parameter == Parameter; 66 | } 67 | 68 | public override int GetHashCode () 69 | { 70 | int hc = Scheme.ToLowerInvariant ().GetHashCode (); 71 | if (!string.IsNullOrEmpty (Parameter)) { 72 | hc ^= Parameter.ToLowerInvariant ().GetHashCode (); 73 | } 74 | 75 | return hc; 76 | } 77 | 78 | public static AuthenticationHeaderValue Parse (string input) 79 | { 80 | AuthenticationHeaderValue value; 81 | if (TryParse (input, out value)) 82 | return value; 83 | 84 | throw new FormatException (input); 85 | } 86 | 87 | public static bool TryParse (string input, out AuthenticationHeaderValue parsedValue) 88 | { 89 | var lexer = new Lexer (input); 90 | Token token; 91 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 92 | return true; 93 | 94 | parsedValue = null; 95 | return false; 96 | } 97 | 98 | internal static bool TryParse (string input, int minimalCount, out List result) 99 | { 100 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 101 | } 102 | 103 | static bool TryParseElement (Lexer lexer, out AuthenticationHeaderValue parsedValue, out Token t) 104 | { 105 | t = lexer.Scan (); 106 | if (t != Token.Type.Token) { 107 | parsedValue = null; 108 | return false; 109 | } 110 | 111 | parsedValue = new AuthenticationHeaderValue (); 112 | parsedValue.Scheme = lexer.GetStringValue (t); 113 | 114 | t = lexer.Scan (); 115 | if (t == Token.Type.Token) { 116 | // TODO: Wrong with multi value parsing 117 | parsedValue.Parameter = lexer.GetRemainingStringValue (t.StartPosition); 118 | t = new Token (Token.Type.End, 0, 0); 119 | } 120 | 121 | return true; 122 | } 123 | 124 | public override string ToString () 125 | { 126 | return Parameter != null ? 127 | Scheme + " " + Parameter : 128 | Scheme; 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionExtensions.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | using System.Text; 32 | 33 | namespace System.Net.Http.Headers 34 | { 35 | static class CollectionExtensions 36 | { 37 | public static bool SequenceEqual (this List first, List second) 38 | { 39 | if (first == null) 40 | return second == null || second.Count == 0; 41 | 42 | if (second == null) 43 | return first == null || first.Count == 0; 44 | 45 | return Enumerable.SequenceEqual (first, second); 46 | } 47 | 48 | public static void SetValue (this List parameters, string key, string value) 49 | { 50 | for (int i = 0; i < parameters.Count; ++i) { 51 | var entry = parameters[i]; 52 | if (!string.Equals (entry.Name, key, StringComparison.OrdinalIgnoreCase)) 53 | continue; 54 | 55 | if (value == null) { 56 | parameters.RemoveAt (i); 57 | } else { 58 | parameters[i].Value = value; 59 | } 60 | 61 | return; 62 | } 63 | 64 | if (!string.IsNullOrEmpty (value)) 65 | parameters.Add (new NameValueHeaderValue (key, value)); 66 | } 67 | 68 | public static string ToString (this List list) 69 | { 70 | if (list == null || list.Count == 0) 71 | return null; 72 | 73 | const string separator = "; "; 74 | 75 | var sb = new StringBuilder (); 76 | for (int i = 0; i < list.Count; ++i) { 77 | sb.Append (separator); 78 | sb.Append (list [i]); 79 | } 80 | 81 | return sb.ToString (); 82 | } 83 | 84 | public static void ToStringBuilder (this List list, StringBuilder sb) 85 | { 86 | if (list == null || list.Count == 0) 87 | return; 88 | 89 | const string separator = ", "; 90 | 91 | for (int i = 0; i < list.Count; ++i) { 92 | if (i > 0) { 93 | sb.Append (separator); 94 | } 95 | 96 | sb.Append (list[i]); 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/CollectionParser.cs: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionParser.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | delegate bool ElementTryParser (Lexer lexer, out T parsedValue, out Token token); 34 | 35 | static class CollectionParser 36 | { 37 | public static bool TryParse (string input, int minimalCount, ElementTryParser parser, out List result) where T : class 38 | { 39 | var lexer = new Lexer (input); 40 | result = new List (); 41 | 42 | while (true) { 43 | Token token; 44 | T parsedValue; 45 | if (!parser (lexer, out parsedValue, out token)) 46 | return false; 47 | 48 | if (parsedValue != null) 49 | result.Add (parsedValue); 50 | 51 | if (token == Token.Type.SeparatorComma) 52 | continue; 53 | 54 | if (token == Token.Type.End) { 55 | if (minimalCount > result.Count) { 56 | result = null; 57 | return false; 58 | } 59 | 60 | return true; 61 | } 62 | 63 | result = null; 64 | return false; 65 | } 66 | } 67 | 68 | public static bool TryParse (string input, int minimalCount, out List result) 69 | { 70 | return TryParse (input, minimalCount, TryParseStringElement, out result); 71 | } 72 | 73 | public static bool TryParseRepetition (string input, int minimalCount, out List result) 74 | { 75 | return TryParseRepetition (input, minimalCount, TryParseStringElement, out result); 76 | } 77 | 78 | static bool TryParseStringElement (Lexer lexer, out string parsedValue, out Token t) 79 | { 80 | t = lexer.Scan (); 81 | if (t == Token.Type.Token) { 82 | parsedValue = lexer.GetStringValue (t); 83 | if (parsedValue.Length == 0) 84 | parsedValue = null; 85 | 86 | t = lexer.Scan (); 87 | } else { 88 | parsedValue = null; 89 | } 90 | 91 | return true; 92 | } 93 | 94 | public static bool TryParseRepetition (string input, int minimalCount, ElementTryParser parser, out List result) where T : class 95 | { 96 | var lexer = new Lexer (input); 97 | result = new List (); 98 | 99 | while (true) { 100 | Token token; 101 | T parsedValue; 102 | if (!parser (lexer, out parsedValue, out token)) 103 | return false; 104 | 105 | if (parsedValue != null) 106 | result.Add (parsedValue); 107 | 108 | if (token == Token.Type.End) { 109 | if (minimalCount > result.Count) 110 | return false; 111 | 112 | return true; 113 | } 114 | } 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/EntityTagHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // EntityTagHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class EntityTagHeaderValue : ICloneable 34 | { 35 | static readonly EntityTagHeaderValue any = new EntityTagHeaderValue () { Tag = "*" }; 36 | 37 | public EntityTagHeaderValue (string tag) 38 | { 39 | Parser.Token.CheckQuotedString (tag); 40 | Tag = tag; 41 | } 42 | 43 | public EntityTagHeaderValue (string tag, bool isWeak) 44 | : this (tag) 45 | { 46 | IsWeak = isWeak; 47 | } 48 | 49 | internal EntityTagHeaderValue () 50 | { 51 | } 52 | 53 | public static EntityTagHeaderValue Any { 54 | get { 55 | return any; 56 | } 57 | } 58 | 59 | public bool IsWeak { get; internal set; } 60 | public string Tag { get; internal set; } 61 | 62 | object ICloneable.Clone () 63 | { 64 | return MemberwiseClone (); 65 | } 66 | 67 | public override bool Equals (object obj) 68 | { 69 | var source = obj as EntityTagHeaderValue; 70 | return source != null && source.Tag == Tag && 71 | string.Equals (source.Tag, Tag, StringComparison.Ordinal); 72 | } 73 | 74 | public override int GetHashCode () 75 | { 76 | return IsWeak.GetHashCode () ^ Tag.GetHashCode (); 77 | } 78 | 79 | public static EntityTagHeaderValue Parse (string input) 80 | { 81 | EntityTagHeaderValue value; 82 | if (TryParse (input, out value)) 83 | return value; 84 | 85 | throw new FormatException (input); 86 | } 87 | 88 | public static bool TryParse (string input, out EntityTagHeaderValue parsedValue) 89 | { 90 | var lexer = new Lexer (input); 91 | Token token; 92 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 93 | return true; 94 | 95 | parsedValue = null; 96 | return false; 97 | } 98 | 99 | static bool TryParseElement (Lexer lexer, out EntityTagHeaderValue parsedValue, out Token t) 100 | { 101 | parsedValue = null; 102 | 103 | t = lexer.Scan (); 104 | bool is_weak = false; 105 | 106 | if (t == Token.Type.Token) { 107 | var s = lexer.GetStringValue (t); 108 | if (s == "*") { 109 | parsedValue = any; 110 | 111 | t = lexer.Scan (); 112 | return true; 113 | } 114 | 115 | if (s != "W" || lexer.PeekChar () != '/') 116 | return false; 117 | 118 | is_weak = true; 119 | lexer.EatChar (); 120 | t = lexer.Scan (); 121 | } 122 | 123 | if (t != Token.Type.QuotedString) 124 | return false; 125 | 126 | parsedValue = new EntityTagHeaderValue (); 127 | parsedValue.Tag = lexer.GetStringValue (t); 128 | parsedValue.IsWeak = is_weak; 129 | 130 | t = lexer.Scan (); 131 | 132 | return true; 133 | } 134 | 135 | internal static bool TryParse (string input, int minimalCount, out List result) 136 | { 137 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 138 | } 139 | 140 | public override string ToString () 141 | { 142 | return IsWeak ? 143 | "W/" + Tag : 144 | Tag; 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/HashCodeCalculator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HashCodeCalculator.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | static class HashCodeCalculator 34 | { 35 | public static int Calculate (ICollection list) 36 | { 37 | if (list == null) 38 | return 0; 39 | 40 | int hash = 17; 41 | foreach (var item in list) { 42 | unchecked { 43 | hash = hash * 29 + item.GetHashCode (); 44 | } 45 | } 46 | 47 | return hash; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HeaderInfo.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011, 2014 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Diagnostics; 31 | 32 | namespace System.Net.Http.Headers 33 | { 34 | delegate bool TryParseDelegate (string value, out T result); 35 | delegate bool TryParseListDelegate (string value, int minimalCount, out List result); 36 | 37 | abstract class HeaderInfo 38 | { 39 | class HeaderTypeInfo : HeaderInfo where U : class 40 | { 41 | readonly TryParseDelegate parser; 42 | 43 | public HeaderTypeInfo (string name, TryParseDelegate parser, HttpHeaderKind headerKind) 44 | : base (name, headerKind) 45 | { 46 | this.parser = parser; 47 | } 48 | 49 | public override void AddToCollection (object collection, object value) 50 | { 51 | Debug.Assert (AllowsMany); 52 | 53 | var c = (HttpHeaderValueCollection) collection; 54 | 55 | var list = value as List; 56 | if (list != null) 57 | c.AddRange (list); 58 | else 59 | c.Add ((U) value); 60 | } 61 | 62 | protected override object CreateCollection (HttpHeaders headers, HeaderInfo headerInfo) 63 | { 64 | return new HttpHeaderValueCollection (headers, headerInfo); 65 | } 66 | 67 | public override List ToStringCollection (object collection) 68 | { 69 | if (collection == null) 70 | return null; 71 | 72 | var c = (HttpHeaderValueCollection) collection; 73 | if (c.Count == 0) 74 | return null; 75 | 76 | var list = new List (); 77 | foreach (var item in c) { 78 | list.Add (item.ToString ()); 79 | } 80 | 81 | return list; 82 | } 83 | 84 | public override bool TryParse (string value, out object result) 85 | { 86 | T tresult; 87 | bool b = parser (value, out tresult); 88 | result = tresult; 89 | return b; 90 | } 91 | } 92 | 93 | class CollectionHeaderTypeInfo : HeaderTypeInfo where U : class 94 | { 95 | readonly int minimalCount; 96 | TryParseListDelegate parser; 97 | 98 | public CollectionHeaderTypeInfo (string name, TryParseListDelegate parser, HttpHeaderKind headerKind, int minimalCount) 99 | : base (name, null, headerKind) 100 | { 101 | this.parser = parser; 102 | this.minimalCount = minimalCount; 103 | AllowsMany = true; 104 | } 105 | 106 | public override bool TryParse (string value, out object result) 107 | { 108 | List tresult; 109 | if (!parser (value, minimalCount, out tresult)) { 110 | result = null; 111 | return false; 112 | } 113 | 114 | result = tresult; 115 | return true; 116 | } 117 | } 118 | 119 | public bool AllowsMany; 120 | public readonly HttpHeaderKind HeaderKind; 121 | public readonly string Name; 122 | 123 | protected HeaderInfo (string name, HttpHeaderKind headerKind) 124 | { 125 | this.Name = name; 126 | this.HeaderKind = headerKind; 127 | } 128 | 129 | public static HeaderInfo CreateSingle (string name, TryParseDelegate parser, HttpHeaderKind headerKind) 130 | { 131 | return new HeaderTypeInfo (name, parser, headerKind); 132 | } 133 | 134 | // 135 | // Headers with #rule for defining lists of elements or *rule for defining occurences of elements 136 | // 137 | public static HeaderInfo CreateMulti (string name, TryParseListDelegate elementParser, HttpHeaderKind headerKind, int minimalCount = 1) where T : class 138 | { 139 | return new CollectionHeaderTypeInfo (name, elementParser, headerKind, minimalCount); 140 | } 141 | 142 | public object CreateCollection (HttpHeaders headers) 143 | { 144 | return CreateCollection (headers, this); 145 | } 146 | 147 | public abstract void AddToCollection (object collection, object value); 148 | protected abstract object CreateCollection (HttpHeaders headers, HeaderInfo headerInfo); 149 | public abstract List ToStringCollection (object collection); 150 | public abstract bool TryParse (string value, out object result); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/HttpContentHeaders.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpContentHeaders.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public sealed class HttpContentHeaders : HttpHeaders 34 | { 35 | readonly HttpContent content; 36 | 37 | internal HttpContentHeaders (HttpContent content) 38 | : base (HttpHeaderKind.Content) 39 | { 40 | this.content = content; 41 | } 42 | 43 | public ICollection Allow { 44 | get { 45 | return GetValues ("Allow"); 46 | } 47 | } 48 | 49 | public ICollection ContentEncoding { 50 | get { 51 | return GetValues ("Content-Encoding"); 52 | } 53 | } 54 | 55 | public ContentDispositionHeaderValue ContentDisposition { 56 | get { 57 | return GetValue ("Content-Disposition"); 58 | } 59 | set { 60 | AddOrRemove ("Content-Disposition", value); 61 | } 62 | } 63 | 64 | public ICollection ContentLanguage { 65 | get { 66 | return GetValues ("Content-Language"); 67 | } 68 | } 69 | 70 | public long? ContentLength { 71 | get { 72 | long? v = GetValue ("Content-Length"); 73 | if (v != null) 74 | return v; 75 | 76 | v = content.LoadedBufferLength; 77 | if (v != null) 78 | return v; 79 | 80 | long l; 81 | if (content.TryComputeLength (out l)) 82 | return l; 83 | 84 | return null; 85 | } 86 | set { 87 | AddOrRemove ("Content-Length", value); 88 | } 89 | } 90 | 91 | public Uri ContentLocation { 92 | get { 93 | return GetValue ("Content-Location"); 94 | } 95 | set { 96 | AddOrRemove ("Content-Location", value); 97 | } 98 | } 99 | 100 | public byte[] ContentMD5 { 101 | get { 102 | return GetValue ("Content-MD5"); 103 | } 104 | set { 105 | AddOrRemove ("Content-MD5", value, Parser.MD5.ToString); 106 | } 107 | } 108 | 109 | public ContentRangeHeaderValue ContentRange { 110 | get { 111 | return GetValue ("Content-Range"); 112 | } 113 | set { 114 | AddOrRemove ("Content-Range", value); 115 | } 116 | } 117 | 118 | public MediaTypeHeaderValue ContentType { 119 | get { 120 | return GetValue ("Content-Type"); 121 | } 122 | set { 123 | AddOrRemove ("Content-Type", value); 124 | } 125 | } 126 | 127 | public DateTimeOffset? Expires { 128 | get { 129 | return GetValue ("Expires"); 130 | } 131 | set { 132 | AddOrRemove ("Expires", value, Parser.DateTime.ToString); 133 | } 134 | } 135 | 136 | public DateTimeOffset? LastModified { 137 | get { 138 | return GetValue ("Last-Modified"); 139 | } 140 | set { 141 | AddOrRemove ("Last-Modified", value, Parser.DateTime.ToString); 142 | } 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/HttpHeaderKind.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpHeaderKind.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | namespace System.Net.Http.Headers 30 | { 31 | [Flags] 32 | enum HttpHeaderKind 33 | { 34 | None = 0, 35 | Request = 1, 36 | Response = 1 << 1, 37 | Content = 1 << 2 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/HttpHeaderValueCollection.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpHeaderValueCollection.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections; 30 | using System.Collections.Generic; 31 | 32 | namespace System.Net.Http.Headers 33 | { 34 | public sealed class HttpHeaderValueCollection : ICollection where T : class 35 | { 36 | readonly List list; 37 | readonly HttpHeaders headers; 38 | readonly HeaderInfo headerInfo; 39 | 40 | internal HttpHeaderValueCollection (HttpHeaders headers, HeaderInfo headerInfo) 41 | { 42 | list = new List (); 43 | this.headers = headers; 44 | this.headerInfo = headerInfo; 45 | } 46 | 47 | public int Count { 48 | get { 49 | return list.Count; 50 | } 51 | } 52 | 53 | public bool IsReadOnly { 54 | get { 55 | return false; 56 | } 57 | } 58 | 59 | public void Add (T item) 60 | { 61 | list.Add (item); 62 | } 63 | 64 | internal void AddRange (List values) 65 | { 66 | list.AddRange (values); 67 | } 68 | 69 | public void Clear () 70 | { 71 | list.Clear (); 72 | } 73 | 74 | public bool Contains (T item) 75 | { 76 | return list.Contains (item); 77 | } 78 | 79 | public void CopyTo (T[] array, int arrayIndex) 80 | { 81 | list.CopyTo (array, arrayIndex); 82 | } 83 | 84 | public void ParseAdd (string input) 85 | { 86 | headers.AddValue (input, headerInfo, false); 87 | } 88 | 89 | public bool Remove (T item) 90 | { 91 | return list.Remove (item); 92 | } 93 | 94 | public override string ToString () 95 | { 96 | // This implementation prints different values than 97 | // what .NET does when one of the values is invalid 98 | // But it better represents what is actually hold by 99 | // the collection 100 | return StringEx.Join (", ", list); 101 | } 102 | 103 | public bool TryParseAdd (string input) 104 | { 105 | return headers.AddValue (input, headerInfo, true); 106 | } 107 | 108 | public IEnumerator GetEnumerator () 109 | { 110 | return list.GetEnumerator (); 111 | } 112 | 113 | IEnumerator IEnumerable.GetEnumerator () 114 | { 115 | return GetEnumerator (); 116 | } 117 | 118 | internal T Find (Predicate predicate) 119 | { 120 | return list.Find (predicate); 121 | } 122 | 123 | internal void Remove (Predicate predicate) 124 | { 125 | T item = Find (predicate); 126 | if (item != null) 127 | Remove (item); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/MediaTypeWithQualityHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // MediaTypeWithQualityHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public sealed class MediaTypeWithQualityHeaderValue : MediaTypeHeaderValue 34 | { 35 | public MediaTypeWithQualityHeaderValue (string mediaType) 36 | : base (mediaType) 37 | { 38 | } 39 | 40 | public MediaTypeWithQualityHeaderValue (string mediaType, double quality) 41 | : this (mediaType) 42 | { 43 | Quality = quality; 44 | } 45 | 46 | private MediaTypeWithQualityHeaderValue () 47 | { 48 | } 49 | 50 | public double? Quality { 51 | get { 52 | return QualityValue.GetValue (parameters); 53 | } 54 | set { 55 | QualityValue.SetValue (ref parameters, value); 56 | } 57 | } 58 | 59 | public new static MediaTypeWithQualityHeaderValue Parse (string input) 60 | { 61 | MediaTypeWithQualityHeaderValue value; 62 | if (TryParse (input, out value)) 63 | return value; 64 | 65 | throw new FormatException (); 66 | } 67 | 68 | public static bool TryParse (string input, out MediaTypeWithQualityHeaderValue parsedValue) 69 | { 70 | var lexer = new Lexer (input); 71 | Token token; 72 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 73 | return true; 74 | 75 | parsedValue = null; 76 | return false; 77 | } 78 | 79 | static bool TryParseElement (Lexer lexer, out MediaTypeWithQualityHeaderValue parsedValue, out Token t) 80 | { 81 | parsedValue = null; 82 | 83 | string media; 84 | List parameters = null; 85 | var token = TryParseMediaType (lexer, out media); 86 | if (token == null) { 87 | t = Token.Empty; 88 | return false; 89 | } 90 | 91 | t = token.Value; 92 | if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters (lexer, out parameters, out t) || t != Token.Type.End)) 93 | return false; 94 | 95 | parsedValue = new MediaTypeWithQualityHeaderValue (); 96 | parsedValue.media_type = media; 97 | parsedValue.parameters = parameters; 98 | return true; 99 | } 100 | 101 | internal static bool TryParse (string input, int minimalCount, out List result) 102 | { 103 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/NameValueWithParametersHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // NameValueWithParametersHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class NameValueWithParametersHeaderValue : NameValueHeaderValue, ICloneable 34 | { 35 | List parameters; 36 | 37 | public NameValueWithParametersHeaderValue (string name) 38 | : base (name) 39 | { 40 | } 41 | 42 | public NameValueWithParametersHeaderValue (string name, string value) 43 | : base (name, value) 44 | { 45 | } 46 | 47 | protected NameValueWithParametersHeaderValue (NameValueWithParametersHeaderValue source) 48 | : base (source) 49 | { 50 | if (source.parameters != null) { 51 | foreach (var item in source.parameters) 52 | Parameters.Add (item); 53 | } 54 | } 55 | 56 | private NameValueWithParametersHeaderValue () 57 | : base () 58 | { 59 | } 60 | 61 | public ICollection Parameters { 62 | get { 63 | return parameters ?? (parameters = new List ()); 64 | } 65 | } 66 | 67 | object ICloneable.Clone () 68 | { 69 | return new NameValueWithParametersHeaderValue (this); 70 | } 71 | 72 | public override bool Equals (object obj) 73 | { 74 | var source = obj as NameValueWithParametersHeaderValue; 75 | if (source == null) 76 | return false; 77 | 78 | return base.Equals (obj) && source.parameters.SequenceEqual (parameters); 79 | } 80 | 81 | public override int GetHashCode () 82 | { 83 | return base.GetHashCode () ^ HashCodeCalculator.Calculate (parameters); 84 | } 85 | 86 | public static new NameValueWithParametersHeaderValue Parse (string input) 87 | { 88 | NameValueWithParametersHeaderValue value; 89 | if (TryParse (input, out value)) 90 | return value; 91 | 92 | throw new FormatException (input); 93 | } 94 | 95 | public override string ToString () 96 | { 97 | if (parameters == null || parameters.Count == 0) 98 | return base.ToString (); 99 | 100 | return base.ToString () + CollectionExtensions.ToString (parameters); 101 | } 102 | 103 | public static bool TryParse (string input, out NameValueWithParametersHeaderValue parsedValue) 104 | { 105 | var lexer = new Lexer (input); 106 | Token token; 107 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 108 | return true; 109 | 110 | parsedValue = null; 111 | return false; 112 | } 113 | 114 | internal static bool TryParse (string input, int minimalCount, out List result) 115 | { 116 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 117 | } 118 | 119 | static bool TryParseElement (Lexer lexer, out NameValueWithParametersHeaderValue parsedValue, out Token t) 120 | { 121 | parsedValue = null; 122 | 123 | t = lexer.Scan (); 124 | if (t != Token.Type.Token) 125 | return false; 126 | 127 | parsedValue = new NameValueWithParametersHeaderValue () { 128 | Name = lexer.GetStringValue (t), 129 | }; 130 | 131 | t = lexer.Scan (); 132 | if (t == Token.Type.SeparatorEqual) { 133 | t = lexer.Scan (); 134 | 135 | if (t == Token.Type.Token || t == Token.Type.QuotedString) { 136 | parsedValue.value = lexer.GetStringValue (t); 137 | t = lexer.Scan (); 138 | } else { 139 | return false; 140 | } 141 | } 142 | 143 | if (t == Token.Type.SeparatorSemicolon) { 144 | List result; 145 | if (!TryParseParameters (lexer, out result, out t)) 146 | return false; 147 | 148 | parsedValue.parameters = result; 149 | } 150 | 151 | return true; 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/ProductHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ProductHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class ProductHeaderValue : ICloneable 34 | { 35 | public ProductHeaderValue (string name) 36 | { 37 | Parser.Token.Check (name); 38 | Name = name; 39 | } 40 | 41 | public ProductHeaderValue (string name, string version) 42 | : this (name) 43 | { 44 | if (version != null) 45 | Parser.Token.Check (version); 46 | 47 | Version = version; 48 | } 49 | 50 | internal ProductHeaderValue () 51 | { 52 | } 53 | 54 | public string Name { get; internal set; } 55 | public string Version { get; internal set; } 56 | 57 | object ICloneable.Clone () 58 | { 59 | return MemberwiseClone (); 60 | } 61 | 62 | public override bool Equals (object obj) 63 | { 64 | var source = obj as ProductHeaderValue; 65 | if (source == null) 66 | return false; 67 | 68 | return string.Equals (source.Name, Name, StringComparison.OrdinalIgnoreCase) && 69 | string.Equals (source.Version, Version, StringComparison.OrdinalIgnoreCase); 70 | } 71 | 72 | public override int GetHashCode () 73 | { 74 | var hc = Name.ToLowerInvariant ().GetHashCode (); 75 | if (Version != null) 76 | hc ^= Version.ToLowerInvariant ().GetHashCode (); 77 | 78 | return hc; 79 | } 80 | 81 | public static ProductHeaderValue Parse (string input) 82 | { 83 | ProductHeaderValue value; 84 | if (TryParse (input, out value)) 85 | return value; 86 | 87 | throw new FormatException (input); 88 | } 89 | 90 | public static bool TryParse (string input, out ProductHeaderValue parsedValue) 91 | { 92 | var lexer = new Lexer (input); 93 | Token token; 94 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 95 | return true; 96 | 97 | parsedValue = null; 98 | return false; 99 | } 100 | 101 | internal static bool TryParse (string input, int minimalCount, out List result) 102 | { 103 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 104 | } 105 | 106 | static bool TryParseElement (Lexer lexer, out ProductHeaderValue parsedValue, out Token t) 107 | { 108 | parsedValue = null; 109 | 110 | t = lexer.Scan (); 111 | if (t != Token.Type.Token) 112 | return false; 113 | 114 | parsedValue = new ProductHeaderValue (); 115 | parsedValue.Name = lexer.GetStringValue (t); 116 | 117 | t = lexer.Scan (); 118 | if (t == Token.Type.SeparatorSlash) { 119 | t = lexer.Scan (); 120 | if (t != Token.Type.Token) 121 | return false; 122 | 123 | parsedValue.Version = lexer.GetStringValue (t); 124 | t = lexer.Scan (); 125 | } 126 | 127 | return true; 128 | } 129 | 130 | public override string ToString () 131 | { 132 | return Version == null ? Name : Name + "/" + Version; 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/QualityValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // QualityValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Globalization; 31 | 32 | namespace System.Net.Http.Headers 33 | { 34 | static class QualityValue 35 | { 36 | public static double? GetValue (List parameters) 37 | { 38 | if (parameters == null) 39 | return null; 40 | 41 | var found = parameters.Find (l => string.Equals (l.Name, "q", StringComparison.OrdinalIgnoreCase)); 42 | if (found == null) 43 | return null; 44 | 45 | double value; 46 | if (!double.TryParse (found.Value, NumberStyles.Number, NumberFormatInfo.InvariantInfo, out value)) 47 | return null; 48 | 49 | return value; 50 | } 51 | 52 | public static void SetValue (ref List parameters, double? value) 53 | { 54 | if (value < 0 || value > 1) 55 | throw new ArgumentOutOfRangeException ("Quality"); 56 | 57 | if (parameters == null) 58 | parameters = new List (); 59 | 60 | parameters.SetValue ("q", value == null ? null : value.Value.ToString (NumberFormatInfo.InvariantInfo)); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/RangeConditionHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // RangeConditionHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Globalization; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class RangeConditionHeaderValue : ICloneable 34 | { 35 | public RangeConditionHeaderValue (DateTimeOffset date) 36 | { 37 | Date = date; 38 | } 39 | 40 | public RangeConditionHeaderValue (EntityTagHeaderValue entityTag) 41 | { 42 | if (entityTag == null) 43 | throw new ArgumentNullException ("entityTag"); 44 | 45 | EntityTag = entityTag; 46 | } 47 | 48 | public RangeConditionHeaderValue (string entityTag) 49 | : this (new EntityTagHeaderValue (entityTag)) 50 | { 51 | } 52 | 53 | public DateTimeOffset? Date { get; private set; } 54 | public EntityTagHeaderValue EntityTag { get; private set; } 55 | 56 | object ICloneable.Clone () 57 | { 58 | return MemberwiseClone (); 59 | } 60 | 61 | public override bool Equals (object obj) 62 | { 63 | var source = obj as RangeConditionHeaderValue; 64 | if (source == null) 65 | return false; 66 | 67 | return EntityTag != null ? 68 | EntityTag.Equals (source.EntityTag) : 69 | Date == source.Date; 70 | } 71 | 72 | public override int GetHashCode () 73 | { 74 | return EntityTag != null ? EntityTag.GetHashCode () : Date.GetHashCode (); 75 | } 76 | 77 | public static RangeConditionHeaderValue Parse (string input) 78 | { 79 | RangeConditionHeaderValue value; 80 | if (TryParse (input, out value)) 81 | return value; 82 | 83 | throw new FormatException (input); 84 | } 85 | 86 | public static bool TryParse (string input, out RangeConditionHeaderValue parsedValue) 87 | { 88 | parsedValue = null; 89 | 90 | var lexer = new Lexer (input); 91 | var t = lexer.Scan (); 92 | bool is_weak; 93 | 94 | if (t == Token.Type.Token) { 95 | if (lexer.GetStringValue (t) != "W") { 96 | DateTimeOffset date; 97 | if (!Lexer.TryGetDateValue (input, out date)) 98 | return false; 99 | 100 | parsedValue = new RangeConditionHeaderValue (date); 101 | return true; 102 | } 103 | 104 | if (lexer.PeekChar () != '/') 105 | return false; 106 | 107 | is_weak = true; 108 | lexer.EatChar (); 109 | t = lexer.Scan (); 110 | } else { 111 | is_weak = false; 112 | } 113 | 114 | if (t != Token.Type.QuotedString) 115 | return false; 116 | 117 | if (lexer.Scan () != Token.Type.End) 118 | return false; 119 | 120 | parsedValue = new RangeConditionHeaderValue ( 121 | new EntityTagHeaderValue () { 122 | Tag = lexer.GetStringValue (t), 123 | IsWeak = is_weak 124 | }); 125 | 126 | return true; 127 | } 128 | 129 | public override string ToString () 130 | { 131 | if (EntityTag != null) 132 | return EntityTag.ToString (); 133 | 134 | return Date.Value.ToString ("r", CultureInfo.InvariantCulture); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/RangeItemHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // RangeItemHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | namespace System.Net.Http.Headers 30 | { 31 | public class RangeItemHeaderValue : ICloneable 32 | { 33 | public RangeItemHeaderValue (long? from, long? to) 34 | { 35 | if (from == null && to == null) 36 | throw new ArgumentException (); 37 | 38 | if (from != null && to != null && from > to) { 39 | throw new ArgumentOutOfRangeException ("from"); 40 | } 41 | 42 | if (from < 0) 43 | throw new ArgumentOutOfRangeException ("from"); 44 | 45 | if (to < 0) 46 | throw new ArgumentOutOfRangeException ("to"); 47 | 48 | From = from; 49 | To = to; 50 | } 51 | 52 | public long? From { get; private set; } 53 | public long? To { get; private set; } 54 | 55 | object ICloneable.Clone () 56 | { 57 | return MemberwiseClone (); 58 | } 59 | 60 | public override bool Equals (object obj) 61 | { 62 | var source = obj as RangeItemHeaderValue; 63 | return source != null && source.From == From && source.To == To; 64 | } 65 | 66 | public override int GetHashCode () 67 | { 68 | return From.GetHashCode () ^ To.GetHashCode (); 69 | } 70 | 71 | public override string ToString () 72 | { 73 | if (From == null) 74 | return "-" + To.Value; 75 | 76 | if (To == null) 77 | return From.Value + "-"; 78 | 79 | return From.Value + "-" + To.Value; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/RetryConditionHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // RetryConditionHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Globalization; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class RetryConditionHeaderValue : ICloneable 34 | { 35 | public RetryConditionHeaderValue (DateTimeOffset date) 36 | { 37 | Date = date; 38 | } 39 | 40 | public RetryConditionHeaderValue (TimeSpan delta) 41 | { 42 | if (delta.TotalSeconds > uint.MaxValue) 43 | throw new ArgumentOutOfRangeException ("delta"); 44 | 45 | Delta = delta; 46 | } 47 | 48 | public DateTimeOffset? Date { get; private set; } 49 | public TimeSpan? Delta { get; private set; } 50 | 51 | object ICloneable.Clone () 52 | { 53 | return MemberwiseClone (); 54 | } 55 | 56 | public override bool Equals (object obj) 57 | { 58 | var source = obj as RetryConditionHeaderValue; 59 | return source != null && source.Date == Date && source.Delta == Delta; 60 | } 61 | 62 | public override int GetHashCode () 63 | { 64 | return Date.GetHashCode () ^ Delta.GetHashCode (); 65 | } 66 | 67 | public static RetryConditionHeaderValue Parse (string input) 68 | { 69 | RetryConditionHeaderValue value; 70 | if (TryParse (input, out value)) 71 | return value; 72 | 73 | throw new FormatException (input); 74 | } 75 | 76 | public static bool TryParse (string input, out RetryConditionHeaderValue parsedValue) 77 | { 78 | parsedValue = null; 79 | 80 | var lexer = new Lexer (input); 81 | var t = lexer.Scan (); 82 | if (t != Token.Type.Token) 83 | return false; 84 | 85 | var ts = lexer.TryGetTimeSpanValue (t); 86 | if (ts != null) { 87 | if (lexer.Scan () != Token.Type.End) 88 | return false; 89 | 90 | parsedValue = new RetryConditionHeaderValue (ts.Value); 91 | } else { 92 | DateTimeOffset date; 93 | if (!Lexer.TryGetDateValue (input, out date)) 94 | return false; 95 | 96 | parsedValue = new RetryConditionHeaderValue (date); 97 | } 98 | 99 | return true; 100 | } 101 | 102 | public override string ToString () 103 | { 104 | return Delta != null ? 105 | Delta.Value.TotalSeconds.ToString (CultureInfo.InvariantCulture) : 106 | Date.Value.ToString ("r", CultureInfo.InvariantCulture); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/StringWithQualityHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // StringWithQualityHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Globalization; 31 | 32 | namespace System.Net.Http.Headers 33 | { 34 | public class StringWithQualityHeaderValue : ICloneable 35 | { 36 | public StringWithQualityHeaderValue (string value) 37 | { 38 | Parser.Token.Check (value); 39 | this.Value = value; 40 | } 41 | 42 | public StringWithQualityHeaderValue (string value, double quality) 43 | : this (value) 44 | { 45 | if (quality < 0 || quality > 1) 46 | throw new ArgumentOutOfRangeException ("quality"); 47 | 48 | Quality = quality; 49 | } 50 | 51 | private StringWithQualityHeaderValue () 52 | { 53 | } 54 | 55 | public double? Quality { get; private set; } 56 | public string Value { get; private set; } 57 | 58 | object ICloneable.Clone () 59 | { 60 | return MemberwiseClone (); 61 | } 62 | 63 | public override bool Equals (object obj) 64 | { 65 | var source = obj as StringWithQualityHeaderValue; 66 | return source != null && 67 | string.Equals (source.Value, Value, StringComparison.OrdinalIgnoreCase) && 68 | source.Quality == Quality; 69 | } 70 | 71 | public override int GetHashCode () 72 | { 73 | return Value.ToLowerInvariant ().GetHashCode () ^ Quality.GetHashCode (); 74 | } 75 | 76 | public static StringWithQualityHeaderValue Parse (string input) 77 | { 78 | StringWithQualityHeaderValue value; 79 | if (TryParse (input, out value)) 80 | return value; 81 | 82 | throw new FormatException (input); 83 | } 84 | 85 | public static bool TryParse (string input, out StringWithQualityHeaderValue parsedValue) 86 | { 87 | var lexer = new Lexer (input); 88 | Token token; 89 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 90 | return true; 91 | 92 | parsedValue = null; 93 | return false; 94 | } 95 | 96 | internal static bool TryParse (string input, int minimalCount, out List result) 97 | { 98 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 99 | } 100 | 101 | static bool TryParseElement (Lexer lexer, out StringWithQualityHeaderValue parsedValue, out Token t) 102 | { 103 | parsedValue = null; 104 | t = lexer.Scan (); 105 | if (t != Token.Type.Token) 106 | return false; 107 | 108 | var value = new StringWithQualityHeaderValue (); 109 | value.Value = lexer.GetStringValue (t); 110 | 111 | t = lexer.Scan (); 112 | if (t == Token.Type.SeparatorSemicolon) { 113 | t = lexer.Scan (); 114 | if (t != Token.Type.Token) 115 | return false; 116 | 117 | var s = lexer.GetStringValue (t); 118 | if (s != "q" && s != "Q") 119 | return false; 120 | 121 | t = lexer.Scan (); 122 | if (t != Token.Type.SeparatorEqual) 123 | return false; 124 | 125 | t = lexer.Scan (); 126 | 127 | double d; 128 | if (!lexer.TryGetDoubleValue (t, out d)) 129 | return false; 130 | 131 | if (d > 1) 132 | return false; 133 | 134 | value.Quality = d; 135 | 136 | t = lexer.Scan (); 137 | } 138 | 139 | parsedValue = value; 140 | return true; 141 | } 142 | 143 | public override string ToString () 144 | { 145 | if (Quality != null) 146 | return Value + "; q=" + Quality.Value.ToString ("0.0##", CultureInfo.InvariantCulture); 147 | 148 | return Value; 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/TransferCodingHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // TransferCodingHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public class TransferCodingHeaderValue : ICloneable 34 | { 35 | internal string value; 36 | internal List parameters; 37 | 38 | public TransferCodingHeaderValue (string value) 39 | { 40 | Parser.Token.Check (value); 41 | this.value = value; 42 | } 43 | 44 | protected TransferCodingHeaderValue (TransferCodingHeaderValue source) 45 | { 46 | this.value = source.value; 47 | if (source.parameters != null) { 48 | foreach (var p in source.parameters) { 49 | Parameters.Add (new NameValueHeaderValue (p)); 50 | } 51 | } 52 | } 53 | 54 | internal TransferCodingHeaderValue () 55 | { 56 | } 57 | 58 | public ICollection Parameters { 59 | get { 60 | return parameters ?? (parameters = new List ()); 61 | } 62 | } 63 | 64 | public string Value { 65 | get { 66 | return value; 67 | } 68 | } 69 | 70 | object ICloneable.Clone () 71 | { 72 | return new TransferCodingHeaderValue (this); 73 | } 74 | 75 | public override bool Equals (object obj) 76 | { 77 | var fchv = obj as TransferCodingHeaderValue; 78 | return fchv != null && 79 | string.Equals (value, fchv.value, StringComparison.OrdinalIgnoreCase) && 80 | parameters.SequenceEqual (fchv.parameters); 81 | } 82 | 83 | public override int GetHashCode () 84 | { 85 | var hc = value.ToLowerInvariant ().GetHashCode (); 86 | if (parameters != null) 87 | hc ^= HashCodeCalculator.Calculate (parameters); 88 | 89 | return hc; 90 | } 91 | 92 | public static TransferCodingHeaderValue Parse (string input) 93 | { 94 | TransferCodingHeaderValue value; 95 | 96 | if (TryParse (input, out value)) 97 | return value; 98 | 99 | throw new FormatException (input); 100 | } 101 | 102 | public override string ToString () 103 | { 104 | return value + CollectionExtensions.ToString (parameters); 105 | } 106 | 107 | public static bool TryParse (string input, out TransferCodingHeaderValue parsedValue) 108 | { 109 | var lexer = new Lexer (input); 110 | Token token; 111 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 112 | return true; 113 | 114 | parsedValue = null; 115 | return false; 116 | } 117 | 118 | internal static bool TryParse (string input, int minimalCount, out List result) 119 | { 120 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 121 | } 122 | 123 | static bool TryParseElement (Lexer lexer, out TransferCodingHeaderValue parsedValue, out Token t) 124 | { 125 | parsedValue = null; 126 | 127 | t = lexer.Scan (); 128 | if (t != Token.Type.Token) 129 | return false; 130 | 131 | var result = new TransferCodingHeaderValue (); 132 | result.value = lexer.GetStringValue (t); 133 | 134 | t = lexer.Scan (); 135 | 136 | // Parameters parsing 137 | if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters (lexer, out result.parameters, out t) || t != Token.Type.End)) 138 | return false; 139 | 140 | parsedValue = result; 141 | return true; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.Headers/TransferCodingWithQualityHeaderValue.cs: -------------------------------------------------------------------------------- 1 | // 2 | // TransferCodingWithQualityHeaderValue.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | 31 | namespace System.Net.Http.Headers 32 | { 33 | public sealed class TransferCodingWithQualityHeaderValue : TransferCodingHeaderValue 34 | { 35 | public TransferCodingWithQualityHeaderValue (string value) 36 | : base (value) 37 | { 38 | } 39 | 40 | public TransferCodingWithQualityHeaderValue (string value, double quality) 41 | : this (value) 42 | { 43 | Quality = quality; 44 | } 45 | 46 | private TransferCodingWithQualityHeaderValue () 47 | { 48 | } 49 | 50 | public double? Quality { 51 | get { 52 | return QualityValue.GetValue (parameters); 53 | } 54 | set { 55 | QualityValue.SetValue (ref parameters, value); 56 | } 57 | } 58 | 59 | public new static TransferCodingWithQualityHeaderValue Parse (string input) 60 | { 61 | TransferCodingWithQualityHeaderValue value; 62 | if (TryParse (input, out value)) 63 | return value; 64 | 65 | throw new FormatException (); 66 | } 67 | 68 | public static bool TryParse (string input, out TransferCodingWithQualityHeaderValue parsedValue) 69 | { 70 | var lexer = new Lexer (input); 71 | Token token; 72 | if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) 73 | return true; 74 | 75 | parsedValue = null; 76 | return false; 77 | } 78 | 79 | internal static bool TryParse (string input, int minimalCount, out List result) 80 | { 81 | return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result); 82 | } 83 | 84 | static bool TryParseElement (Lexer lexer, out TransferCodingWithQualityHeaderValue parsedValue, out Token t) 85 | { 86 | parsedValue = null; 87 | 88 | t = lexer.Scan (); 89 | if (t != Token.Type.Token) 90 | return false; 91 | 92 | var result = new TransferCodingWithQualityHeaderValue (); 93 | result.value = lexer.GetStringValue (t); 94 | 95 | t = lexer.Scan (); 96 | 97 | // Parameters parsing 98 | if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters (lexer, out result.parameters, out t) || t != Token.Type.End)) 99 | return false; 100 | 101 | parsedValue = result; 102 | return true; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http.dll.sources: -------------------------------------------------------------------------------- 1 | ../../build/common/Consts.cs 2 | Assembly/AssemblyInfo.cs 3 | System.Net.Http/ByteArrayContent.cs 4 | System.Net.Http/ClientCertificateOption.cs 5 | System.Net.Http/DelegatingHandler.cs 6 | System.Net.Http/FormUrlEncodedContent.cs 7 | System.Net.Http/HttpClient.cs 8 | System.Net.Http/HttpClientHandler.cs 9 | System.Net.Http/HttpCompletionOption.cs 10 | System.Net.Http/HttpContent.cs 11 | System.Net.Http/HttpMessageHandler.cs 12 | System.Net.Http/HttpMessageInvoker.cs 13 | System.Net.Http/HttpMethod.cs 14 | System.Net.Http/HttpRequestException.cs 15 | System.Net.Http/HttpRequestMessage.cs 16 | System.Net.Http/HttpResponseMessage.cs 17 | System.Net.Http/MessageProcessingHandler.cs 18 | System.Net.Http/MultipartContent.cs 19 | System.Net.Http/MultipartFormDataContent.cs 20 | System.Net.Http/StreamContent.cs 21 | System.Net.Http/StringContent.cs 22 | System.Net.Http.Headers/AuthenticationHeaderValue.cs 23 | System.Net.Http.Headers/CacheControlHeaderValue.cs 24 | System.Net.Http.Headers/CollectionExtensions.cs 25 | System.Net.Http.Headers/CollectionParser.cs 26 | System.Net.Http.Headers/ContentDispositionHeaderValue.cs 27 | System.Net.Http.Headers/ContentRangeHeaderValue.cs 28 | System.Net.Http.Headers/EntityTagHeaderValue.cs 29 | System.Net.Http.Headers/HashCodeCalculator.cs 30 | System.Net.Http.Headers/HeaderInfo.cs 31 | System.Net.Http.Headers/HttpContentHeaders.cs 32 | System.Net.Http.Headers/HttpHeaderKind.cs 33 | System.Net.Http.Headers/HttpHeaders.cs 34 | System.Net.Http.Headers/HttpHeaderValueCollection.cs 35 | System.Net.Http.Headers/HttpRequestHeaders.cs 36 | System.Net.Http.Headers/HttpResponseHeaders.cs 37 | System.Net.Http.Headers/Lexer.cs 38 | System.Net.Http.Headers/MediaTypeHeaderValue.cs 39 | System.Net.Http.Headers/MediaTypeWithQualityHeaderValue.cs 40 | System.Net.Http.Headers/NameValueHeaderValue.cs 41 | System.Net.Http.Headers/NameValueWithParametersHeaderValue.cs 42 | System.Net.Http.Headers/Parser.cs 43 | System.Net.Http.Headers/ProductHeaderValue.cs 44 | System.Net.Http.Headers/ProductInfoHeaderValue.cs 45 | System.Net.Http.Headers/QualityValue.cs 46 | System.Net.Http.Headers/RangeConditionHeaderValue.cs 47 | System.Net.Http.Headers/RangeHeaderValue.cs 48 | System.Net.Http.Headers/RangeItemHeaderValue.cs 49 | System.Net.Http.Headers/RetryConditionHeaderValue.cs 50 | System.Net.Http.Headers/StringWithQualityHeaderValue.cs 51 | System.Net.Http.Headers/TransferCodingHeaderValue.cs 52 | System.Net.Http.Headers/TransferCodingWithQualityHeaderValue.cs 53 | System.Net.Http.Headers/ViaHeaderValue.cs 54 | System.Net.Http.Headers/WarningHeaderValue.cs -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/ByteArrayContent.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ByteArrayContent.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.IO; 30 | using System.Threading.Tasks; 31 | using Rackspace.Threading; 32 | 33 | namespace System.Net.Http 34 | { 35 | public class ByteArrayContent: HttpContent 36 | { 37 | readonly byte[] content; 38 | readonly int offset, count; 39 | 40 | public ByteArrayContent (byte[] content) 41 | { 42 | if (content == null) 43 | throw new ArgumentNullException ("content"); 44 | 45 | this.content = content; 46 | this.count = content.Length; 47 | } 48 | 49 | public ByteArrayContent (byte[] content, int offset, int count) 50 | : this (content) 51 | { 52 | if (offset < 0 || offset > this.count) 53 | throw new ArgumentOutOfRangeException ("offset"); 54 | 55 | if (count < 0 || count > (this.count - offset)) 56 | throw new ArgumentOutOfRangeException ("count"); 57 | 58 | this.offset = offset; 59 | this.count = count; 60 | } 61 | 62 | protected override Task CreateContentReadStreamAsync () 63 | { 64 | return CompletedTask.FromResult (new MemoryStream (content, offset, count)); 65 | } 66 | 67 | protected internal override Task SerializeToStreamAsync (Stream stream, TransportContext context) 68 | { 69 | return stream.WriteAsync (content, offset, count); 70 | } 71 | 72 | protected internal override bool TryComputeLength (out long length) 73 | { 74 | length = count; 75 | return true; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/ClientCertificateOption.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ClientCertificateOption.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | namespace System.Net.Http 30 | { 31 | public enum ClientCertificateOption 32 | { 33 | Manual, 34 | Automatic 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/DelegatingHandler.cs: -------------------------------------------------------------------------------- 1 | // 2 | // DelegatingHandler.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Threading; 30 | using System.Threading.Tasks; 31 | 32 | namespace System.Net.Http 33 | { 34 | public abstract class DelegatingHandler : HttpMessageHandler 35 | { 36 | bool disposed; 37 | HttpMessageHandler handler; 38 | 39 | protected DelegatingHandler () 40 | { 41 | } 42 | 43 | protected DelegatingHandler(HttpMessageHandler innerHandler) 44 | { 45 | if (innerHandler == null) 46 | throw new ArgumentNullException ("innerHandler"); 47 | 48 | InnerHandler = innerHandler; 49 | } 50 | 51 | public HttpMessageHandler InnerHandler { 52 | get { 53 | return handler; 54 | } 55 | set { 56 | if (value == null) 57 | throw new ArgumentNullException ("InnerHandler"); 58 | 59 | handler = value; 60 | } 61 | } 62 | 63 | protected override void Dispose (bool disposing) 64 | { 65 | if (disposing && !disposed) { 66 | disposed = true; 67 | if (InnerHandler != null) 68 | InnerHandler.Dispose (); 69 | } 70 | 71 | base.Dispose (disposing); 72 | } 73 | 74 | protected internal override Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) 75 | { 76 | return InnerHandler.SendAsync (request, cancellationToken); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/FormUrlEncodedContent.cs: -------------------------------------------------------------------------------- 1 | // 2 | // FormUrlEncodedContent.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Net.Http.Headers; 31 | using System.Text; 32 | 33 | namespace System.Net.Http 34 | { 35 | public class FormUrlEncodedContent : ByteArrayContent 36 | { 37 | public FormUrlEncodedContent (IEnumerable> nameValueCollection) 38 | : base (EncodeContent (nameValueCollection)) 39 | { 40 | Headers.ContentType = new MediaTypeHeaderValue ("application/x-www-form-urlencoded"); 41 | } 42 | 43 | static byte[] EncodeContent (IEnumerable> nameValueCollection) 44 | { 45 | if (nameValueCollection == null) 46 | throw new ArgumentNullException ("nameValueCollection"); 47 | 48 | // 49 | // Serialization as application/x-www-form-urlencoded 50 | // 51 | // Element nodes selected for inclusion are encoded as EltName=value{sep}, where = is a literal 52 | // character, {sep} is the separator character from the separator attribute on submission, 53 | // EltName represents the element local name, and value represents the contents of the text node. 54 | // 55 | // The encoding of EltName and value are as follows: space characters are replaced by +, and then 56 | // non-ASCII and reserved characters (as defined by [RFC 2396] as amended by subsequent documents 57 | // in the IETF track) are escaped by replacing the character with one or more octets of the UTF-8 58 | // representation of the character, with each octet in turn replaced by %HH, where HH represents 59 | // the uppercase hexadecimal notation for the octet value and % is a literal character. Line breaks 60 | // are represented as "CR LF" pairs (i.e., %0D%0A). 61 | // 62 | var sb = new List (); 63 | foreach (var item in nameValueCollection) { 64 | if (sb.Count != 0) 65 | sb.Add ((byte) '&'); 66 | 67 | var data = SerializeValue (item.Key); 68 | if (data != null) 69 | sb.AddRange (data); 70 | sb.Add ((byte) '='); 71 | 72 | data = SerializeValue (item.Value); 73 | if (data != null) 74 | sb.AddRange (data); 75 | } 76 | 77 | return sb.ToArray (); 78 | } 79 | 80 | static byte[] SerializeValue (string value) 81 | { 82 | if (value == null) 83 | return null; 84 | 85 | value = Uri.EscapeDataString (value).Replace ("%20", "+"); 86 | return Encoding.ASCII.GetBytes (value); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/HttpCompletionOption.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpCompletionOption.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | namespace System.Net.Http 30 | { 31 | public enum HttpCompletionOption 32 | { 33 | ResponseContentRead, 34 | ResponseHeadersRead 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/HttpMessageHandler.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpMessageHandler.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Threading; 30 | using System.Threading.Tasks; 31 | 32 | namespace System.Net.Http 33 | { 34 | public abstract class HttpMessageHandler : IDisposable 35 | { 36 | public void Dispose () 37 | { 38 | Dispose (true); 39 | } 40 | 41 | protected virtual void Dispose (bool disposing) 42 | { 43 | } 44 | 45 | protected internal abstract Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/HttpMessageInvoker.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpMessageInvoker.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Threading; 30 | using System.Threading.Tasks; 31 | 32 | namespace System.Net.Http 33 | { 34 | public class HttpMessageInvoker : IDisposable 35 | { 36 | HttpMessageHandler handler; 37 | readonly bool disposeHandler; 38 | 39 | public HttpMessageInvoker (HttpMessageHandler handler) 40 | : this (handler, true) 41 | { 42 | } 43 | 44 | public HttpMessageInvoker (HttpMessageHandler handler, bool disposeHandler) 45 | { 46 | if (handler == null) 47 | throw new ArgumentNullException ("handler"); 48 | 49 | this.handler = handler; 50 | this.disposeHandler = disposeHandler; 51 | } 52 | 53 | public void Dispose () 54 | { 55 | Dispose (true); 56 | } 57 | 58 | protected virtual void Dispose (bool disposing) 59 | { 60 | if (disposing && disposeHandler && handler != null) { 61 | handler.Dispose (); 62 | handler = null; 63 | } 64 | } 65 | 66 | public virtual Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) 67 | { 68 | return handler.SendAsync (request, cancellationToken); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/HttpMethod.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpMethod.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | namespace System.Net.Http 30 | { 31 | public class HttpMethod : IEquatable 32 | { 33 | static readonly HttpMethod delete_method = new HttpMethod ("DELETE"); 34 | static readonly HttpMethod get_method = new HttpMethod ("GET"); 35 | static readonly HttpMethod head_method = new HttpMethod ("HEAD"); 36 | static readonly HttpMethod options_method = new HttpMethod ("OPTIONS"); 37 | static readonly HttpMethod post_method = new HttpMethod ("POST"); 38 | static readonly HttpMethod put_method = new HttpMethod ("PUT"); 39 | static readonly HttpMethod trace_method = new HttpMethod ("TRACE"); 40 | 41 | readonly string method; 42 | 43 | public HttpMethod (string method) 44 | { 45 | if (string.IsNullOrEmpty (method)) 46 | throw new ArgumentException ("method"); 47 | 48 | Headers.Parser.Token.Check (method); 49 | 50 | this.method = method; 51 | } 52 | 53 | public static HttpMethod Delete { 54 | get { 55 | return delete_method; 56 | } 57 | } 58 | 59 | public static HttpMethod Get { 60 | get { 61 | return get_method; 62 | } 63 | } 64 | 65 | public static HttpMethod Head { 66 | get { 67 | return head_method; 68 | } 69 | } 70 | 71 | public string Method { 72 | get { 73 | return method; 74 | } 75 | } 76 | 77 | public static HttpMethod Options { 78 | get { 79 | return options_method; 80 | } 81 | } 82 | 83 | public static HttpMethod Post { 84 | get { 85 | return post_method; 86 | } 87 | } 88 | 89 | public static HttpMethod Put { 90 | get { 91 | return put_method; 92 | } 93 | } 94 | 95 | public static HttpMethod Trace { 96 | get { 97 | return trace_method; 98 | } 99 | } 100 | 101 | public static bool operator == (HttpMethod left, HttpMethod right) 102 | { 103 | if ((object) left == null || (object) right == null) 104 | return ReferenceEquals (left, right); 105 | 106 | return left.Equals (right); 107 | } 108 | 109 | public static bool operator != (HttpMethod left, HttpMethod right) 110 | { 111 | return !(left == right); 112 | } 113 | 114 | public bool Equals(HttpMethod other) 115 | { 116 | return string.Equals (method, other.method, StringComparison.OrdinalIgnoreCase); 117 | } 118 | 119 | public override bool Equals (object obj) 120 | { 121 | var other = obj as HttpMethod; 122 | return !ReferenceEquals (other, null) && Equals (other); 123 | } 124 | 125 | public override int GetHashCode () 126 | { 127 | return method.GetHashCode (); 128 | } 129 | 130 | public override string ToString () 131 | { 132 | return method; 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/HttpRequestException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpRequestException.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | namespace System.Net.Http 30 | { 31 | [Serializable] 32 | public class HttpRequestException : Exception 33 | { 34 | public HttpRequestException () 35 | { 36 | } 37 | 38 | public HttpRequestException (string message) 39 | : base (message) 40 | { 41 | } 42 | 43 | public HttpRequestException (string message, Exception inner) 44 | : base (message, inner) 45 | { 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/HttpRequestMessage.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpRequestMessage.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Net.Http.Headers; 31 | using System.Text; 32 | 33 | namespace System.Net.Http 34 | { 35 | public class HttpRequestMessage : IDisposable 36 | { 37 | HttpRequestHeaders headers; 38 | HttpMethod method; 39 | Version version; 40 | Dictionary properties; 41 | Uri uri; 42 | bool is_used; 43 | bool disposed; 44 | 45 | public HttpRequestMessage () 46 | { 47 | this.method = HttpMethod.Get; 48 | } 49 | 50 | public HttpRequestMessage (HttpMethod method, string requestUri) 51 | : this (method, string.IsNullOrEmpty (requestUri) ? (Uri) null : new Uri (requestUri, System.UriKind.RelativeOrAbsolute)) 52 | { 53 | } 54 | 55 | public HttpRequestMessage (HttpMethod method, Uri requestUri) 56 | { 57 | Method = method; 58 | RequestUri = requestUri; 59 | } 60 | 61 | public HttpContent Content { get; set; } 62 | 63 | public HttpRequestHeaders Headers { 64 | get { 65 | return headers ?? (headers = new HttpRequestHeaders ()); 66 | } 67 | } 68 | 69 | public HttpMethod Method { 70 | get { 71 | return method; 72 | } 73 | set { 74 | if (value == null) 75 | throw new ArgumentNullException ("method"); 76 | 77 | method = value; 78 | } 79 | } 80 | 81 | public IDictionary Properties { 82 | get { 83 | return properties ?? (properties = new Dictionary ()); 84 | } 85 | } 86 | 87 | public Uri RequestUri { 88 | get { 89 | return uri; 90 | } 91 | set { 92 | if (value != null && (value.IsAbsoluteUri && value.Scheme != Uri.UriSchemeHttp && value.Scheme != Uri.UriSchemeHttps)) 93 | throw new ArgumentException ("Only http or https scheme is allowed"); 94 | 95 | uri = value; 96 | } 97 | } 98 | 99 | public Version Version { 100 | get { 101 | return version ?? HttpVersion.Version11; 102 | } 103 | set { 104 | if (value == null) 105 | throw new ArgumentNullException ("Version"); 106 | 107 | version = value; 108 | } 109 | } 110 | 111 | public void Dispose () 112 | { 113 | Dispose (true); 114 | } 115 | 116 | protected virtual void Dispose (bool disposing) 117 | { 118 | if (disposing && !disposed) { 119 | disposed = true; 120 | 121 | if (Content != null) 122 | Content.Dispose (); 123 | } 124 | } 125 | 126 | internal bool SetIsUsed () 127 | { 128 | if (is_used) 129 | return true; 130 | 131 | is_used = true; 132 | return false; 133 | } 134 | 135 | public override string ToString () 136 | { 137 | var sb = new StringBuilder (); 138 | sb.Append ("Method: ").Append (method); 139 | sb.Append (", RequestUri: '").Append (RequestUri != null ? RequestUri.ToString () : ""); 140 | sb.Append ("', Version: ").Append (Version); 141 | sb.Append (", Content: ").Append (Content != null ? Content.ToString () : ""); 142 | sb.Append (", Headers:\r\n{\r\n").Append (Headers); 143 | if (Content != null) 144 | sb.Append (Content.Headers); 145 | sb.Append ("}"); 146 | 147 | return sb.ToString (); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/MessageProcessingHandler.cs: -------------------------------------------------------------------------------- 1 | // 2 | // MessageProcessingHandler.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Threading; 30 | using System.Threading.Tasks; 31 | using Rackspace.Threading; 32 | 33 | namespace System.Net.Http 34 | { 35 | public abstract class MessageProcessingHandler : DelegatingHandler 36 | { 37 | protected MessageProcessingHandler () 38 | { 39 | } 40 | 41 | protected MessageProcessingHandler (HttpMessageHandler innerHandler) 42 | : base (innerHandler) 43 | { 44 | } 45 | 46 | protected abstract HttpRequestMessage ProcessRequest (HttpRequestMessage request, CancellationToken cancellationToken); 47 | protected abstract HttpResponseMessage ProcessResponse (HttpResponseMessage response, CancellationToken cancellationToken); 48 | 49 | protected internal sealed override Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) 50 | { 51 | // This might be more efficiently implemented with Select(), but that method is unable to correctly translate 52 | // a TaskCanceledException into a TaskStatus.Canceled result. 53 | request = ProcessRequest (request, cancellationToken); 54 | return base.SendAsync (request, cancellationToken) 55 | .Then (task => Task.Factory.StartNew (() => ProcessResponse (task.Result, cancellationToken), cancellationToken)); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/MultipartFormDataContent.cs: -------------------------------------------------------------------------------- 1 | // 2 | // MultipartFormDataContent.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Net.Http.Headers; 30 | 31 | namespace System.Net.Http 32 | { 33 | public class MultipartFormDataContent : MultipartContent 34 | { 35 | public MultipartFormDataContent () 36 | : base ("form-data") 37 | { 38 | } 39 | 40 | public MultipartFormDataContent (string boundary) 41 | : base ("form-data", boundary) 42 | { 43 | } 44 | 45 | public override void Add (HttpContent content) 46 | { 47 | base.Add (content); 48 | AddContentDisposition (content, null, null); 49 | } 50 | 51 | public void Add (HttpContent content, string name) 52 | { 53 | base.Add (content); 54 | 55 | if (StringEx.IsNullOrWhiteSpace (name)) 56 | throw new ArgumentException ("name"); 57 | 58 | AddContentDisposition (content, name, null); 59 | } 60 | 61 | public void Add (HttpContent content, string name, string fileName) 62 | { 63 | base.Add (content); 64 | 65 | if (StringEx.IsNullOrWhiteSpace (name)) 66 | throw new ArgumentException ("name"); 67 | 68 | if (StringEx.IsNullOrWhiteSpace (fileName)) 69 | throw new ArgumentException ("fileName"); 70 | 71 | AddContentDisposition (content, name, fileName); 72 | } 73 | 74 | void AddContentDisposition (HttpContent content, string name, string fileName) 75 | { 76 | var headers = content.Headers; 77 | if (headers.ContentDisposition != null) 78 | return; 79 | 80 | headers.ContentDisposition = new ContentDispositionHeaderValue ("form-data") { 81 | Name = name, 82 | FileName = fileName, 83 | FileNameStar = fileName 84 | }; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/StreamContent.cs: -------------------------------------------------------------------------------- 1 | // 2 | // StreamContent.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.IO; 30 | using System.Threading; 31 | using System.Threading.Tasks; 32 | using Rackspace.Threading; 33 | 34 | namespace System.Net.Http 35 | { 36 | public class StreamContent : HttpContent 37 | { 38 | readonly Stream content; 39 | readonly int bufferSize; 40 | readonly CancellationToken cancellationToken; 41 | 42 | public StreamContent (Stream content) 43 | : this (content, 16 * 1024) 44 | { 45 | } 46 | 47 | public StreamContent (Stream content, int bufferSize) 48 | { 49 | if (content == null) 50 | throw new ArgumentNullException ("content"); 51 | 52 | if (bufferSize <= 0) 53 | throw new ArgumentOutOfRangeException ("bufferSize"); 54 | 55 | this.content = content; 56 | this.bufferSize = bufferSize; 57 | } 58 | 59 | // 60 | // Workarounds for poor .NET API 61 | // Instead of having SerializeToStreamAsync with CancellationToken as public API. Only LoadIntoBufferAsync 62 | // called internally from the send worker can be cancelled and user cannot see/do it 63 | // 64 | internal StreamContent (Stream content, CancellationToken cancellationToken) 65 | : this (content) 66 | { 67 | // We don't own the token so don't worry about disposing it 68 | this.cancellationToken = cancellationToken; 69 | } 70 | 71 | protected override Task CreateContentReadStreamAsync () 72 | { 73 | return CompletedTask.FromResult (content); 74 | } 75 | 76 | protected override void Dispose (bool disposing) 77 | { 78 | if (disposing) { 79 | content.Dispose (); 80 | } 81 | 82 | base.Dispose (disposing); 83 | } 84 | 85 | protected internal override Task SerializeToStreamAsync (Stream stream, TransportContext context) 86 | { 87 | return content.CopyToAsync (stream, bufferSize, cancellationToken); 88 | } 89 | 90 | protected internal override bool TryComputeLength (out long length) 91 | { 92 | if (!content.CanSeek) { 93 | length = 0; 94 | return false; 95 | } 96 | length = content.Length; 97 | return true; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http/StringContent.cs: -------------------------------------------------------------------------------- 1 | // 2 | // StringContent.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System.Text; 30 | using System.Net.Http.Headers; 31 | 32 | namespace System.Net.Http 33 | { 34 | public class StringContent : ByteArrayContent 35 | { 36 | public StringContent (string content) 37 | : this (content, null, null) 38 | { 39 | } 40 | 41 | public StringContent (string content, Encoding encoding) 42 | : this (content, encoding, null) 43 | { 44 | } 45 | 46 | public StringContent (string content, Encoding encoding, string mediaType) 47 | : base (GetByteArray (content, encoding)) 48 | { 49 | Headers.ContentType = new MediaTypeHeaderValue (mediaType ?? "text/plain") { 50 | CharSet = (encoding ?? Encoding.UTF8).WebName 51 | }; 52 | } 53 | 54 | static byte[] GetByteArray (string content, Encoding encoding) 55 | { 56 | return (encoding ?? Encoding.UTF8).GetBytes (content); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /System.Net.Http/System.Net.Http_test.dll.sources: -------------------------------------------------------------------------------- 1 | System.Net.Http/DelegatingHandlerTest.cs 2 | System.Net.Http/ByteArrayContentTest.cs 3 | System.Net.Http/FormUrlEncodedContentTest.cs 4 | System.Net.Http/HttpClientHandlerTest.cs 5 | System.Net.Http/HttpClientTest.cs 6 | System.Net.Http/HttpMethodTest.cs 7 | System.Net.Http/HttpRequestMessageTest.cs 8 | System.Net.Http/HttpResponseMessageTest.cs 9 | System.Net.Http/MultipartContentTest.cs 10 | System.Net.Http/MultipartFormDataContentTest.cs 11 | System.Net.Http/StreamContentTest.cs 12 | System.Net.Http/StringContentTest.cs 13 | System.Net.Http.Headers/AuthenticationHeaderValueTest.cs 14 | System.Net.Http.Headers/CacheControlHeaderValueTest.cs 15 | System.Net.Http.Headers/ContentDispositionHeaderValueTest.cs 16 | System.Net.Http.Headers/ContentRangeHeaderValueTest.cs 17 | System.Net.Http.Headers/EntityTagHeaderValueTest.cs 18 | System.Net.Http.Headers/HttpHeadersTest.cs 19 | System.Net.Http.Headers/HttpHeaderValueCollection.cs 20 | System.Net.Http.Headers/MediaTypeHeaderValueTest.cs 21 | System.Net.Http.Headers/MediaTypeWithQualityHeaderValueTest.cs 22 | System.Net.Http.Headers/NameValueHeaderValueTest.cs 23 | System.Net.Http.Headers/NameValueWithParametersHeaderValueTest.cs 24 | System.Net.Http.Headers/ProductHeaderValueTest.cs 25 | System.Net.Http.Headers/ProductInfoHeaderValueTest.cs 26 | System.Net.Http.Headers/RangeConditionHeaderValueTest.cs 27 | System.Net.Http.Headers/RangeHeaderValueTest.cs 28 | System.Net.Http.Headers/RangeItemHeaderValueTest.cs 29 | System.Net.Http.Headers/RetryConditionHeaderValueTest.cs 30 | System.Net.Http.Headers/StringWithQualityHeaderValueTest.cs 31 | System.Net.Http.Headers/TransferCodingHeaderValueTest.cs 32 | System.Net.Http.Headers/TransferCodingWithQualityHeaderValueTest.cs 33 | System.Net.Http.Headers/ViaHeaderValueTest.cs 34 | System.Net.Http.Headers/WarningHeaderValueTest.cs 35 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/AuthenticationHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // AuthenticationHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class AuthenticationHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new AuthenticationHeaderValue (null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new AuthenticationHeaderValue (" ", null); 51 | Assert.Fail ("#2"); 52 | } catch (FormatException) { 53 | } 54 | } 55 | 56 | [TestMethod] 57 | public void Equals () 58 | { 59 | var value = new AuthenticationHeaderValue ("ab"); 60 | Assert.AreEqual (value, new AuthenticationHeaderValue ("ab"), "#1"); 61 | Assert.AreEqual (value, new AuthenticationHeaderValue ("AB"), "#2"); 62 | Assert.AreNotEqual (value, new AuthenticationHeaderValue ("AA"), "#3"); 63 | 64 | value = new AuthenticationHeaderValue ("ab", "DD"); 65 | Assert.AreEqual (value, new AuthenticationHeaderValue ("Ab", "DD"), "#4"); 66 | Assert.AreNotEqual (value, new AuthenticationHeaderValue ("AB"), "#5"); 67 | Assert.AreNotEqual (value, new AuthenticationHeaderValue ("Ab", "dd"), "#6"); 68 | } 69 | 70 | [TestMethod] 71 | public void Parse () 72 | { 73 | var res = AuthenticationHeaderValue.Parse ("c"); 74 | Assert.AreEqual ("c", res.Scheme, "#1"); 75 | Assert.IsNull (res.Parameter, "#2"); 76 | Assert.AreEqual ("c", res.ToString (), "#3"); 77 | 78 | res = AuthenticationHeaderValue.Parse ("ss p=3 , q = \"vvv\""); 79 | 80 | Assert.AreEqual ("ss", res.Scheme, "#11"); 81 | Assert.AreEqual ("p=3 , q = \"vvv\"", res.Parameter, "#12"); 82 | Assert.AreEqual ("ss p=3 , q = \"vvv\"", res.ToString (), "#13"); 83 | } 84 | 85 | [TestMethod] 86 | public void Parse_Invalid () 87 | { 88 | try { 89 | AuthenticationHeaderValue.Parse (null); 90 | Assert.Fail ("#1"); 91 | } catch (FormatException) { 92 | } 93 | 94 | try { 95 | AuthenticationHeaderValue.Parse (" "); 96 | Assert.Fail ("#2"); 97 | } catch (FormatException) { 98 | } 99 | 100 | try { 101 | AuthenticationHeaderValue.Parse ("a;b"); 102 | Assert.Fail ("#3"); 103 | } catch (FormatException) { 104 | } 105 | } 106 | 107 | [TestMethod] 108 | public void Properties () 109 | { 110 | var value = new AuthenticationHeaderValue ("s", "p"); 111 | Assert.AreEqual ("s", value.Scheme, "#1"); 112 | Assert.AreEqual ("p", value.Parameter, "#2"); 113 | 114 | value = new AuthenticationHeaderValue ("s"); 115 | Assert.AreEqual ("s", value.Scheme, "#3"); 116 | Assert.IsNull (value.Parameter, "#4"); 117 | } 118 | 119 | [TestMethod] 120 | public void TryParse () 121 | { 122 | AuthenticationHeaderValue res; 123 | Assert.IsTrue (AuthenticationHeaderValue.TryParse ("a", out res), "#1"); 124 | Assert.AreEqual ("a", res.Scheme, "#2"); 125 | Assert.IsNull (res.Parameter, "#3"); 126 | } 127 | 128 | [TestMethod] 129 | public void TryParse_Invalid () 130 | { 131 | AuthenticationHeaderValue res; 132 | Assert.IsFalse (AuthenticationHeaderValue.TryParse ("", out res), "#1"); 133 | Assert.IsNull (res, "#2"); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/EntityTagHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // EntityTagHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class EntityTagHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new EntityTagHeaderValue (null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new EntityTagHeaderValue ("a"); 51 | Assert.Fail ("#2"); 52 | } catch (FormatException) { 53 | } 54 | } 55 | 56 | [TestMethod] 57 | public void Equals () 58 | { 59 | var tfhv = new EntityTagHeaderValue ("\"abc\""); 60 | Assert.AreEqual (tfhv, new EntityTagHeaderValue ("\"abc\""), "#1"); 61 | Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AbC\""), "#2"); 62 | Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AA\""), "#3"); 63 | } 64 | 65 | [TestMethod] 66 | public void Parse () 67 | { 68 | var res = EntityTagHeaderValue.Parse ("\"c\""); 69 | Assert.AreEqual ("\"c\"", res.Tag, "#1"); 70 | Assert.IsFalse (res.IsWeak, "#2"); 71 | Assert.AreEqual ("\"c\"", res.ToString (), "#3"); 72 | 73 | res = EntityTagHeaderValue.Parse ("W/ \"mm\""); 74 | Assert.AreEqual ("\"mm\"", res.Tag, "#11"); 75 | Assert.IsTrue (res.IsWeak, "#12"); 76 | Assert.AreEqual ("W/\"mm\"", res.ToString (), "#13"); 77 | } 78 | 79 | [TestMethod] 80 | public void Parse_Invalid () 81 | { 82 | try { 83 | EntityTagHeaderValue.Parse (null); 84 | Assert.Fail ("#1"); 85 | } catch (FormatException) { 86 | } 87 | 88 | try { 89 | EntityTagHeaderValue.Parse (" "); 90 | Assert.Fail ("#2"); 91 | } catch (FormatException) { 92 | } 93 | 94 | try { 95 | EntityTagHeaderValue.Parse ("W / \"a\""); 96 | Assert.Fail ("#3"); 97 | } catch (FormatException) { 98 | } 99 | } 100 | 101 | 102 | [TestMethod] 103 | public void Properties () 104 | { 105 | var etv = new EntityTagHeaderValue ("\"tag\"", true); 106 | Assert.AreEqual ("\"tag\"", etv.Tag, "#1"); 107 | Assert.IsTrue (etv.IsWeak, "#2"); 108 | 109 | Assert.AreEqual ("*", EntityTagHeaderValue.Any.Tag, "#3"); 110 | Assert.IsFalse (EntityTagHeaderValue.Any.IsWeak, "#4"); 111 | } 112 | 113 | [TestMethod] 114 | public void TryParse () 115 | { 116 | EntityTagHeaderValue res; 117 | Assert.IsTrue (EntityTagHeaderValue.TryParse ("\"\"", out res), "#1"); 118 | Assert.AreEqual ("\"\"", res.Tag, "#2"); 119 | } 120 | 121 | [TestMethod] 122 | public void TryParse_Invalid () 123 | { 124 | EntityTagHeaderValue res; 125 | Assert.IsFalse (EntityTagHeaderValue.TryParse ("", out res), "#1"); 126 | Assert.IsNull (res, "#2"); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/HttpHeaderValueCollection.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpHeaderValueCollectionTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using System.Net.Http; 34 | using System.Linq; 35 | using Microsoft.VisualStudio.TestTools.UnitTesting; 36 | 37 | namespace MonoTests.System.Net.Http.Headers 38 | { 39 | [TestClass] 40 | public class HttpHeaderValueCollectionTest 41 | { 42 | [TestMethod] 43 | public void ParseAdd () 44 | { 45 | HttpRequestMessage message = new HttpRequestMessage (); 46 | HttpRequestHeaders headers = message.Headers; 47 | 48 | headers.TE.ParseAdd ("pp"); 49 | Assert.AreEqual ("pp", headers.TE.ToArray ()[0].Value, "#1"); 50 | Assert.AreEqual (1, headers.TE.Count); 51 | } 52 | 53 | [TestMethod] 54 | public void ParseAdd_Invalid () 55 | { 56 | HttpRequestMessage message = new HttpRequestMessage (); 57 | HttpRequestHeaders headers = message.Headers; 58 | 59 | try { 60 | headers.Via.ParseAdd ("pp"); 61 | } catch (FormatException) { 62 | } 63 | } 64 | 65 | [TestMethod] 66 | public void TryParseAdd () 67 | { 68 | HttpRequestMessage message = new HttpRequestMessage (); 69 | HttpRequestHeaders headers = message.Headers; 70 | 71 | Assert.IsTrue (headers.TE.TryParseAdd ("pp"), "#1"); 72 | Assert.AreEqual ("pp", headers.TE.ToArray ()[0].Value, "#2"); 73 | Assert.AreEqual (1, headers.TE.Count, "#3"); 74 | 75 | Assert.IsFalse (headers.Via.TryParseAdd ("wrong"), "#4"); 76 | } 77 | 78 | [TestMethod] 79 | public void ToStringTest () 80 | { 81 | HttpRequestMessage message = new HttpRequestMessage (); 82 | HttpRequestHeaders headers = message.Headers; 83 | 84 | Assert.AreEqual ("", headers.Connection.ToString (), "#1"); 85 | 86 | headers.Connection.Add ("kk"); 87 | 88 | Assert.AreEqual ("kk", headers.Connection.ToString (), "#2"); 89 | 90 | headers.Connection.Add ("ttt"); 91 | 92 | Assert.AreEqual ("kk, ttt", headers.Connection.ToString (), "#3"); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/HttpHeadersTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpHeadersTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using System.Linq; 34 | using Microsoft.VisualStudio.TestTools.UnitTesting; 35 | 36 | namespace MonoTests.System.Net.Http.Headers 37 | { 38 | [TestClass] 39 | public class HttpHeadersTest 40 | { 41 | HttpHeaders headers; 42 | 43 | class HttpHeadersMock : HttpHeaders 44 | { 45 | } 46 | 47 | [TestInitialize] 48 | public void Setup () 49 | { 50 | headers = new HttpHeadersMock (); 51 | } 52 | 53 | [TestMethod] 54 | public void Add () 55 | { 56 | headers.Add ("aa", "value"); 57 | headers.Add ("aa", "value"); 58 | headers.Add ("Expires", (string) null); 59 | } 60 | 61 | [TestMethod] 62 | public void Add_InvalidArguments () 63 | { 64 | try { 65 | headers.Add (null, "value"); 66 | Assert.Fail ("#1"); 67 | } catch (ArgumentException) { 68 | } 69 | 70 | try { 71 | headers.Add ("", "value"); 72 | Assert.Fail ("#2"); 73 | } catch (ArgumentException) { 74 | } 75 | } 76 | 77 | [TestMethod] 78 | public void Clear () 79 | { 80 | headers.Add ("aa", "value"); 81 | headers.Clear (); 82 | } 83 | 84 | [TestMethod] 85 | public void GetEnumerator () 86 | { 87 | headers.Add ("aa", "value"); 88 | int i = 0; 89 | foreach (var entry in headers) { 90 | ++i; 91 | Assert.AreEqual ("aa", entry.Key); 92 | var values = entry.Value.ToList (); 93 | Assert.AreEqual (1, values.Count); 94 | Assert.AreEqual ("value", values[0]); 95 | } 96 | 97 | Assert.AreEqual (1, i, "#10"); 98 | } 99 | 100 | [TestMethod] 101 | public void GetValues () 102 | { 103 | headers.Add ("aa", "v"); 104 | headers.Add ("aa", "v"); 105 | 106 | var r = headers.GetValues ("aa").ToList (); 107 | Assert.AreEqual ("v", r[0], "#1"); 108 | Assert.AreEqual ("v", r[1], "#2"); 109 | } 110 | 111 | [TestMethod] 112 | public void GetValues_Invalid () 113 | { 114 | try { 115 | headers.GetValues (null); 116 | Assert.Fail ("#1"); 117 | } catch (ArgumentException) { 118 | } 119 | 120 | try { 121 | headers.GetValues (" "); 122 | Assert.Fail ("#2"); 123 | } catch (FormatException) { 124 | } 125 | 126 | try { 127 | headers.GetValues ("x"); 128 | Assert.Fail ("#3"); 129 | } catch (InvalidOperationException) { 130 | } 131 | } 132 | 133 | [TestMethod] 134 | public void TryGetValuesTest () 135 | { 136 | IEnumerable headerValues; 137 | Assert.IsFalse (headers.TryGetValues (null, out headerValues), "#1"); 138 | Assert.IsFalse (headers.TryGetValues ("some-name", out headerValues), "#2"); 139 | } 140 | 141 | [TestMethod] 142 | public void ToStringTest () 143 | { 144 | headers.Add ("aa", "v"); 145 | headers.Add ("aa", "v"); 146 | headers.Add ("x", "v"); 147 | 148 | Assert.AreEqual ("aa: v, v\r\nx: v\r\n", headers.ToString ()); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/MediaTypeHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // MediaTypeHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class MediaTypeHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new MediaTypeHeaderValue (null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new MediaTypeHeaderValue (" "); 51 | Assert.Fail ("#2"); 52 | } catch (FormatException) { 53 | } 54 | } 55 | 56 | [TestMethod] 57 | public void Equals () 58 | { 59 | var value = new MediaTypeHeaderValue ("multipart/*"); 60 | Assert.AreEqual (value, new MediaTypeHeaderValue ("multipart/*"), "#1"); 61 | Assert.AreEqual (value, new MediaTypeHeaderValue ("Multipart/*"), "#2"); 62 | Assert.AreNotEqual (value, new MediaTypeHeaderValue ("multipart/A"), "#3"); 63 | 64 | value.CharSet = "chs"; 65 | Assert.AreNotEqual (value, new MediaTypeHeaderValue ("multipart/*"), "#5"); 66 | 67 | var custom_param = new MediaTypeHeaderValue ("Multipart/*"); 68 | custom_param.Parameters.Add (new NameValueHeaderValue ("Charset", "chs")); 69 | Assert.AreEqual (value, custom_param, "#6"); 70 | } 71 | 72 | [TestMethod] 73 | public void Parse () 74 | { 75 | var res = MediaTypeHeaderValue.Parse ("multipart / b* "); 76 | Assert.AreEqual ("multipart/b*", res.MediaType, "#1"); 77 | Assert.IsNull (res.CharSet, "#1b"); 78 | Assert.AreEqual ("multipart/b*", res.ToString (), "#1c"); 79 | 80 | res = MediaTypeHeaderValue.Parse ("mu / m; CHarset=jj' "); 81 | Assert.AreEqual ("mu/m", res.MediaType, "#2"); 82 | Assert.AreEqual ("jj'", res.CharSet, "#2b"); 83 | Assert.AreEqual ("mu/m; CHarset=jj'", res.ToString (), "#2c"); 84 | } 85 | 86 | [TestMethod] 87 | public void Parse_Invalid () 88 | { 89 | try { 90 | MediaTypeHeaderValue.Parse (null); 91 | Assert.Fail ("#1"); 92 | } catch (FormatException) { 93 | } 94 | 95 | try { 96 | MediaTypeHeaderValue.Parse (" "); 97 | Assert.Fail ("#2"); 98 | } catch (FormatException) { 99 | } 100 | 101 | try { 102 | MediaTypeHeaderValue.Parse ("a;b"); 103 | Assert.Fail ("#3"); 104 | } catch (FormatException) { 105 | } 106 | } 107 | 108 | [TestMethod] 109 | public void Properties () 110 | { 111 | var value = new MediaTypeHeaderValue ("multipart/*"); 112 | Assert.AreEqual ("multipart/*", value.MediaType, "#1"); 113 | Assert.IsNull (value.CharSet, "#2"); 114 | Assert.AreEqual (0, value.Parameters.Count, "#3"); 115 | 116 | value.CharSet = "chs"; 117 | Assert.AreEqual ("chs", value.CharSet, "#4"); 118 | 119 | value = new MediaTypeHeaderValue ("multipart/*"); 120 | value.Parameters.Add (new NameValueHeaderValue ("CHarSEt", "te-va")); 121 | Assert.AreEqual ("te-va", value.CharSet, "#5"); 122 | } 123 | 124 | [TestMethod] 125 | public void Properties_Invalid () 126 | { 127 | var value = new MediaTypeHeaderValue ("multipart/*"); 128 | 129 | try { 130 | value.CharSet = ";;"; 131 | Assert.Fail ("#1"); 132 | } catch (FormatException) { 133 | } 134 | 135 | try { 136 | value.MediaType = null; 137 | Assert.Fail ("#2"); 138 | } catch (ArgumentException) { 139 | } 140 | } 141 | 142 | [TestMethod] 143 | public void TryParse () 144 | { 145 | MediaTypeHeaderValue res; 146 | Assert.IsTrue (MediaTypeHeaderValue.TryParse ("multipart/*", out res), "#1"); 147 | Assert.AreEqual ("multipart/*", res.MediaType, "#2"); 148 | Assert.IsNull (res.CharSet, "#3"); 149 | } 150 | 151 | [TestMethod] 152 | public void TryParse_Invalid () 153 | { 154 | MediaTypeHeaderValue res; 155 | Assert.IsFalse (MediaTypeHeaderValue.TryParse ("", out res), "#1"); 156 | Assert.IsNull (res, "#2"); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/MediaTypeWithQualityHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // MediaTypeWithQualityHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using System.Linq; 34 | using Microsoft.VisualStudio.TestTools.UnitTesting; 35 | 36 | namespace MonoTests.System.Net.Http.Headers 37 | { 38 | [TestClass] 39 | public class MediaTypeWithQualityHeaderValueTest 40 | { 41 | [TestMethod] 42 | public void Ctor_InvalidArguments () 43 | { 44 | try { 45 | new MediaTypeWithQualityHeaderValue (null); 46 | Assert.Fail ("#1"); 47 | } catch (ArgumentException) { 48 | } 49 | 50 | try { 51 | new MediaTypeWithQualityHeaderValue ("audio/", 0.1); 52 | Assert.Fail ("#2"); 53 | } catch (FormatException) { 54 | } 55 | 56 | try { 57 | new MediaTypeWithQualityHeaderValue ("audio/*", 2); 58 | Assert.Fail ("#3"); 59 | } catch (ArgumentOutOfRangeException) { 60 | } 61 | } 62 | 63 | [TestMethod] 64 | public void Equals () 65 | { 66 | var value = new MediaTypeWithQualityHeaderValue ("audio/x"); 67 | Assert.AreEqual (value, new MediaTypeWithQualityHeaderValue ("audio/x"), "#1"); 68 | Assert.AreEqual (value, new MediaTypeWithQualityHeaderValue ("aUdio/X"), "#2"); 69 | Assert.AreNotEqual (value, new MediaTypeWithQualityHeaderValue ("audio/y"), "#3"); 70 | 71 | value = new MediaTypeWithQualityHeaderValue ("audio/x", 0.3); 72 | Assert.AreEqual (value, new MediaTypeWithQualityHeaderValue ("audio/x", 0.3), "#4"); 73 | Assert.AreNotEqual (value, new MediaTypeWithQualityHeaderValue ("audio/x"), "#5"); 74 | Assert.AreNotEqual (value, new MediaTypeWithQualityHeaderValue ("audio/Y", 0.6), "#6"); 75 | } 76 | 77 | [TestMethod] 78 | public void Parse () 79 | { 80 | var res = MediaTypeWithQualityHeaderValue.Parse ("audio/ aa"); 81 | Assert.AreEqual ("audio/aa", res.MediaType, "#1"); 82 | Assert.AreEqual (0, res.Parameters.Count, "#1b"); 83 | Assert.AreEqual ("audio/aa", res.ToString (), "#1c"); 84 | } 85 | 86 | [TestMethod] 87 | public void Parse_Invalid () 88 | { 89 | try { 90 | MediaTypeWithQualityHeaderValue.Parse (null); 91 | Assert.Fail ("#1"); 92 | } catch (FormatException) { 93 | } 94 | 95 | try { 96 | MediaTypeWithQualityHeaderValue.Parse (" "); 97 | Assert.Fail ("#2"); 98 | } catch (FormatException) { 99 | } 100 | 101 | try { 102 | MediaTypeWithQualityHeaderValue.Parse ("audio/"); 103 | Assert.Fail ("#3"); 104 | } catch (FormatException) { 105 | } 106 | } 107 | 108 | [TestMethod] 109 | public void Properties () 110 | { 111 | var value = new MediaTypeWithQualityHeaderValue ("audio/*", 0.3); 112 | Assert.IsNull (value.CharSet, "#1"); 113 | Assert.AreEqual ("audio/*", value.MediaType, "#2"); 114 | Assert.AreEqual ("q", value.Parameters.First ().Name, "#3"); 115 | Assert.AreEqual (0.3, value.Quality, "#4"); 116 | 117 | value.Parameters.Add (new NameValueHeaderValue ("q", "b")); 118 | } 119 | 120 | [TestMethod] 121 | public void TryParse () 122 | { 123 | MediaTypeWithQualityHeaderValue res; 124 | Assert.IsTrue (MediaTypeWithQualityHeaderValue.TryParse ("audio/*", out res), "#1"); 125 | Assert.AreEqual (0, res.Parameters.Count, "#1"); 126 | } 127 | 128 | [TestMethod] 129 | public void TryParse_Invalid () 130 | { 131 | MediaTypeWithQualityHeaderValue res; 132 | Assert.IsFalse (MediaTypeWithQualityHeaderValue.TryParse ("", out res), "#1"); 133 | Assert.IsNull (res, "#2"); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/NameValueWithParametersHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // NameValueWithParametersHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using System.Linq; 34 | using Microsoft.VisualStudio.TestTools.UnitTesting; 35 | 36 | namespace MonoTests.System.Net.Http.Headers 37 | { 38 | [TestClass] 39 | public class NameValueWithParametersHeaderValueTest 40 | { 41 | [TestMethod] 42 | public void Ctor_InvalidArguments () 43 | { 44 | try { 45 | new NameValueWithParametersHeaderValue (null); 46 | Assert.Fail ("#1"); 47 | } catch (ArgumentException) { 48 | } 49 | 50 | try { 51 | new NameValueHeaderValue (" ", null); 52 | Assert.Fail ("#2"); 53 | } catch (FormatException) { 54 | } 55 | } 56 | 57 | [TestMethod] 58 | public void Equals () 59 | { 60 | var value = new NameValueWithParametersHeaderValue ("ab"); 61 | Assert.AreEqual (value, new NameValueWithParametersHeaderValue ("ab"), "#1"); 62 | Assert.AreEqual (value, new NameValueWithParametersHeaderValue ("AB"), "#2"); 63 | Assert.AreNotEqual (value, new NameValueWithParametersHeaderValue ("AA"), "#3"); 64 | 65 | var second = new NameValueWithParametersHeaderValue ("AB"); 66 | second.Parameters.Add (new NameValueHeaderValue ("pv")); 67 | 68 | Assert.AreNotEqual (value, second, "#4"); 69 | 70 | value.Parameters.Add (new NameValueHeaderValue ("pv")); 71 | Assert.AreEqual (value, second, "#5"); 72 | } 73 | 74 | [TestMethod] 75 | public void Parse () 76 | { 77 | var res = NameValueWithParametersHeaderValue.Parse ("c"); 78 | Assert.AreEqual ("c", res.Name, "#1"); 79 | Assert.AreEqual ("c", res.ToString (), "#1b"); 80 | Assert.IsNull (res.Value, "#2"); 81 | 82 | res = NameValueWithParametersHeaderValue.Parse ("a=2 ; b = 555"); 83 | Assert.AreEqual ("a", res.Name, "#3"); 84 | Assert.AreEqual ("a=2; b=555", res.ToString (), "#3b"); 85 | Assert.AreEqual ("2", res.Value, "#4"); 86 | Assert.AreEqual ("b", res.Parameters.First().Name, "#5"); 87 | Assert.AreEqual (1, res.Parameters.Count, "#6"); 88 | } 89 | 90 | [TestMethod] 91 | public void Parse_Invalid () 92 | { 93 | try { 94 | NameValueWithParametersHeaderValue.Parse (null); 95 | Assert.Fail ("#1"); 96 | } catch (FormatException) { 97 | } 98 | 99 | try { 100 | NameValueWithParametersHeaderValue.Parse (" "); 101 | Assert.Fail ("#2"); 102 | } catch (FormatException) { 103 | } 104 | 105 | try { 106 | NameValueWithParametersHeaderValue.Parse ("a=1;"); 107 | Assert.Fail ("#3"); 108 | } catch (FormatException) { 109 | } 110 | } 111 | 112 | [TestMethod] 113 | public void Properties () 114 | { 115 | var value = new NameValueWithParametersHeaderValue ("s", "p"); 116 | Assert.AreEqual ("s", value.Name, "#1"); 117 | Assert.AreEqual ("p", value.Value, "#2"); 118 | 119 | value = new NameValueWithParametersHeaderValue ("s"); 120 | Assert.AreEqual ("s", value.Name, "#3"); 121 | Assert.IsNull (value.Value, "#4"); 122 | 123 | value.Value = "bb"; 124 | Assert.AreEqual ("bb", value.Value, "#5"); 125 | } 126 | 127 | [TestMethod] 128 | public void Properties_Invalid () 129 | { 130 | var value = new NameValueWithParametersHeaderValue ("s"); 131 | try { 132 | value.Value = " "; 133 | Assert.Fail ("#1"); 134 | } catch (FormatException) { 135 | } 136 | } 137 | 138 | [TestMethod] 139 | public void TryParse () 140 | { 141 | NameValueWithParametersHeaderValue res; 142 | Assert.IsTrue (NameValueWithParametersHeaderValue.TryParse ("a", out res), "#1"); 143 | Assert.AreEqual ("a", res.Name, "#2"); 144 | Assert.IsNull (res.Value, "#3"); 145 | } 146 | 147 | [TestMethod] 148 | public void TryParse_Invalid () 149 | { 150 | NameValueWithParametersHeaderValue res; 151 | Assert.IsFalse (NameValueWithParametersHeaderValue.TryParse ("", out res), "#1"); 152 | Assert.IsNull (res, "#2"); 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/ProductHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ProductHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class ProductHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new ProductHeaderValue (null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new ProductHeaderValue ("x", " "); 51 | Assert.Fail ("#2"); 52 | } catch (FormatException) { 53 | } 54 | 55 | try { 56 | new ProductHeaderValue ("/"); 57 | Assert.Fail ("#3"); 58 | } catch (FormatException) { 59 | } 60 | } 61 | 62 | [TestMethod] 63 | public void Ctor () 64 | { 65 | new ProductHeaderValue ("aa", null); 66 | } 67 | 68 | [TestMethod] 69 | public void Equals () 70 | { 71 | var value = new ProductHeaderValue ("ab"); 72 | Assert.AreEqual (value, new ProductHeaderValue ("ab"), "#1"); 73 | Assert.AreEqual (value, new ProductHeaderValue ("AB"), "#2"); 74 | Assert.AreNotEqual (value, new ProductHeaderValue ("AA"), "#3"); 75 | 76 | value = new ProductHeaderValue ("ab", "DD"); 77 | Assert.AreEqual (value, new ProductHeaderValue ("Ab", "DD"), "#4"); 78 | Assert.AreNotEqual (value, new ProductHeaderValue ("AB"), "#5"); 79 | Assert.AreEqual (value, new ProductHeaderValue ("Ab", "dd"), "#6"); 80 | } 81 | 82 | [TestMethod] 83 | public void Parse () 84 | { 85 | var res = ProductHeaderValue.Parse ("c"); 86 | Assert.AreEqual ("c", res.Name, "#1"); 87 | Assert.IsNull (res.Version, "#2"); 88 | Assert.AreEqual ("c", res.ToString (), "#3"); 89 | 90 | res = ProductHeaderValue.Parse (" mm / ppp"); 91 | Assert.AreEqual ("mm", res.Name, "#4"); 92 | Assert.AreEqual ("ppp", res.Version, "#5"); 93 | Assert.AreEqual ("mm/ppp", res.ToString (), "#6"); 94 | } 95 | 96 | [TestMethod] 97 | public void Parse_Invalid () 98 | { 99 | try { 100 | ProductHeaderValue.Parse (null); 101 | Assert.Fail ("#1"); 102 | } catch (FormatException) { 103 | } 104 | 105 | try { 106 | ProductHeaderValue.Parse (" "); 107 | Assert.Fail ("#2"); 108 | } catch (FormatException) { 109 | } 110 | 111 | try { 112 | ProductHeaderValue.Parse ("a;b"); 113 | Assert.Fail ("#3"); 114 | } catch (FormatException) { 115 | } 116 | 117 | try { 118 | ProductHeaderValue.Parse ("a/"); 119 | Assert.Fail ("#4"); 120 | } catch (FormatException) { 121 | } 122 | } 123 | 124 | [TestMethod] 125 | public void Properties () 126 | { 127 | var value = new ProductHeaderValue ("s", "p"); 128 | Assert.AreEqual ("s", value.Name, "#1"); 129 | Assert.AreEqual ("p", value.Version, "#2"); 130 | 131 | value = new ProductHeaderValue ("s"); 132 | Assert.AreEqual ("s", value.Name, "#3"); 133 | Assert.IsNull (value.Version, "#4"); 134 | } 135 | 136 | [TestMethod] 137 | public void TryParse () 138 | { 139 | ProductHeaderValue res; 140 | Assert.IsTrue (ProductHeaderValue.TryParse ("a", out res), "#1"); 141 | Assert.AreEqual ("a", res.Name, "#2"); 142 | Assert.IsNull (res.Version, "#3"); 143 | } 144 | 145 | [TestMethod] 146 | public void TryParse_Invalid () 147 | { 148 | ProductHeaderValue res; 149 | Assert.IsFalse (ProductHeaderValue.TryParse ("", out res), "#1"); 150 | Assert.IsNull (res, "#2"); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/ProductInfoHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ProductInfoHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class ProductInfoHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new ProductInfoHeaderValue (null as string); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new ProductInfoHeaderValue (" ", null); 51 | Assert.Fail ("#2"); 52 | } catch (FormatException) { 53 | } 54 | 55 | try { 56 | new ProductInfoHeaderValue (null as ProductHeaderValue); 57 | Assert.Fail ("#3"); 58 | } catch (ArgumentException) { 59 | } 60 | } 61 | 62 | [TestMethod] 63 | public void Equals () 64 | { 65 | var value = new ProductInfoHeaderValue ("(ab)"); 66 | Assert.AreEqual (value, new ProductInfoHeaderValue ("(ab)"), "#1"); 67 | Assert.AreNotEqual (value, new ProductInfoHeaderValue ("(AB)"), "#2"); 68 | Assert.AreNotEqual (value, new ProductInfoHeaderValue ("(AA)"), "#3"); 69 | 70 | value = new ProductInfoHeaderValue ("ab", "DD"); 71 | Assert.AreEqual (value, new ProductInfoHeaderValue ("Ab", "DD"), "#4"); 72 | Assert.AreNotEqual (value, new ProductInfoHeaderValue ("(AB)"), "#5"); 73 | Assert.AreEqual (value, new ProductInfoHeaderValue ("Ab", "dd"), "#6"); 74 | } 75 | 76 | [TestMethod] 77 | public void Parse () 78 | { 79 | var res = ProductInfoHeaderValue.Parse ("c"); 80 | Assert.AreEqual ("c", res.Product.Name, "#1"); 81 | Assert.IsNull (res.Product.Version, "#2"); 82 | Assert.IsNull (res.Comment, "#3"); 83 | Assert.AreEqual ("c", res.ToString (), "#4"); 84 | 85 | res = ProductInfoHeaderValue.Parse (" b / 6"); 86 | Assert.AreEqual ("b", res.Product.Name, "#11"); 87 | Assert.AreEqual ("6", res.Product.Version, "#12"); 88 | Assert.IsNull (res.Comment, "#13"); 89 | Assert.AreEqual ("b/6", res.ToString (), "#14"); 90 | 91 | res = ProductInfoHeaderValue.Parse (" ( cccc ) "); 92 | Assert.IsNull (res.Product, "#21"); 93 | Assert.AreEqual ("( cccc )", res.Comment, "#22"); 94 | Assert.AreEqual ("( cccc )", res.ToString (), "#23"); 95 | } 96 | 97 | [TestMethod] 98 | public void Parse_Invalid () 99 | { 100 | try { 101 | ProductInfoHeaderValue.Parse (null); 102 | Assert.Fail ("#1"); 103 | } catch (FormatException) { 104 | } 105 | 106 | try { 107 | ProductInfoHeaderValue.Parse (" "); 108 | Assert.Fail ("#2"); 109 | } catch (FormatException) { 110 | } 111 | 112 | try { 113 | ProductInfoHeaderValue.Parse ("a;b"); 114 | Assert.Fail ("#3"); 115 | } catch (FormatException) { 116 | } 117 | } 118 | 119 | [TestMethod] 120 | public void Properties () 121 | { 122 | var value = new ProductInfoHeaderValue ("s", "p"); 123 | Assert.AreEqual ("s", value.Product.Name, "#1"); 124 | Assert.AreEqual ("p", value.Product.Version, "#2"); 125 | Assert.IsNull (value.Comment, "#3"); 126 | 127 | value = new ProductInfoHeaderValue ("(s)"); 128 | Assert.AreEqual ("(s)", value.Comment, "#4"); 129 | Assert.IsNull (value.Product, "#5"); 130 | } 131 | 132 | [TestMethod] 133 | public void TryParse () 134 | { 135 | ProductInfoHeaderValue res; 136 | Assert.IsTrue (ProductInfoHeaderValue.TryParse ("a", out res), "#1"); 137 | Assert.AreEqual ("a", res.Product.Name, "#2"); 138 | Assert.IsNull (res.Comment, "#3"); 139 | } 140 | 141 | [TestMethod] 142 | public void TryParse_Invalid () 143 | { 144 | ProductInfoHeaderValue res; 145 | Assert.IsFalse (ProductInfoHeaderValue.TryParse ("", out res), "#1"); 146 | Assert.IsNull (res, "#2"); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/RangeItemHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // RangeItemHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class RangeItemHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new RangeItemHeaderValue (null, null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new RangeItemHeaderValue (5, 2); 51 | Assert.Fail ("#2"); 52 | } catch (ArgumentOutOfRangeException) { 53 | } 54 | 55 | try { 56 | new RangeItemHeaderValue (-1, 2); 57 | Assert.Fail ("#3"); 58 | } catch (ArgumentOutOfRangeException) { 59 | } 60 | } 61 | 62 | [TestMethod] 63 | public void Ctor () 64 | { 65 | var v = new RangeItemHeaderValue (1, null); 66 | Assert.AreEqual ("1-", v.ToString (), "#1"); 67 | 68 | v = new RangeItemHeaderValue (null, 1); 69 | Assert.AreEqual ("-1", v.ToString (), "#2"); 70 | } 71 | 72 | [TestMethod] 73 | public void Equals () 74 | { 75 | var value = new RangeItemHeaderValue (5, null); 76 | Assert.AreEqual (value, new RangeItemHeaderValue (5, null), "#1"); 77 | Assert.AreNotEqual (value, new RangeItemHeaderValue (6, null), "#2"); 78 | Assert.AreNotEqual (value, new RangeItemHeaderValue (5, 10), "#3"); 79 | } 80 | 81 | [TestMethod] 82 | public void Properties () 83 | { 84 | var value = new RangeItemHeaderValue (3, 23); 85 | Assert.AreEqual (3, value.From, "#1"); 86 | Assert.AreEqual (23, value.To, "#2"); 87 | 88 | value = new RangeItemHeaderValue (5, null); 89 | Assert.AreEqual (5, value.From, "#3"); 90 | Assert.IsNull (value.To, "#4"); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/RetryConditionHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // RetryConditionHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http.Headers 36 | { 37 | [TestClass] 38 | public class RetryConditionHeaderValueTest 39 | { 40 | [TestMethod] 41 | public void Ctor_InvalidArguments () 42 | { 43 | try { 44 | new RetryConditionHeaderValue (TimeSpan.MaxValue); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | } 49 | 50 | [TestMethod] 51 | public void Equals () 52 | { 53 | var value = new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today)); 54 | Assert.AreEqual (value, new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today)), "#1"); 55 | Assert.AreNotEqual (value, new RetryConditionHeaderValue (new DateTimeOffset ()), "#2"); 56 | 57 | value = new RetryConditionHeaderValue (new TimeSpan (300)); 58 | Assert.AreEqual (value, new RetryConditionHeaderValue (new TimeSpan (300)), "#4"); 59 | Assert.AreNotEqual (value, new RetryConditionHeaderValue (new TimeSpan (44)), "#5"); 60 | } 61 | 62 | [TestMethod] 63 | public void Parse () 64 | { 65 | var res = RetryConditionHeaderValue.Parse ("144"); 66 | Assert.IsNull (res.Date, "#1"); 67 | Assert.AreEqual (new TimeSpan (0, 0, 144), res.Delta, "#2"); 68 | Assert.AreEqual ("144", res.ToString (), "#3"); 69 | 70 | res = RetryConditionHeaderValue.Parse ("Fri, 31 Dec 1999 23:59:59 GMT"); 71 | Assert.AreEqual (new DateTimeOffset (1999, 12, 31, 23, 59, 59, 0, TimeSpan.Zero), res.Date, "#11"); 72 | Assert.IsNull (res.Delta, "#12"); 73 | Assert.AreEqual ("Fri, 31 Dec 1999 23:59:59 GMT", res.ToString (), "#13"); 74 | } 75 | 76 | [TestMethod] 77 | public void Parse_Invalid () 78 | { 79 | try { 80 | RetryConditionHeaderValue.Parse (null); 81 | Assert.Fail ("#1"); 82 | } catch (FormatException) { 83 | } 84 | 85 | try { 86 | RetryConditionHeaderValue.Parse (" "); 87 | Assert.Fail ("#2"); 88 | } catch (FormatException) { 89 | } 90 | 91 | try { 92 | RetryConditionHeaderValue.Parse ("a"); 93 | Assert.Fail ("#3"); 94 | } catch (FormatException) { 95 | } 96 | } 97 | 98 | [TestMethod] 99 | public void Properties () 100 | { 101 | var value = new RetryConditionHeaderValue (new TimeSpan (5000)); 102 | Assert.IsNull (value.Date, "#1"); 103 | Assert.AreEqual (new TimeSpan (5000), value.Delta, "#2"); 104 | 105 | value = new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today)); 106 | Assert.AreEqual (new DateTimeOffset (DateTime.Today), value.Date, "#3"); 107 | Assert.IsNull (value.Delta, "#4"); 108 | } 109 | 110 | [TestMethod] 111 | public void TryParse () 112 | { 113 | RetryConditionHeaderValue res; 114 | Assert.IsTrue (RetryConditionHeaderValue.TryParse ("124", out res), "#1"); 115 | Assert.IsNull (res.Date, "#2"); 116 | Assert.AreEqual (new TimeSpan (0, 2, 4), res.Delta, "#3"); 117 | } 118 | 119 | [TestMethod] 120 | public void TryParse_Invalid () 121 | { 122 | RetryConditionHeaderValue res; 123 | Assert.IsFalse (RetryConditionHeaderValue.TryParse ("", out res), "#1"); 124 | Assert.IsNull (res, "#2"); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http.Headers/TransferCodingWithQualityHeaderValueTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // TransferCodingWithQualityHeaderValueTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http.Headers; 33 | using System.Linq; 34 | using Microsoft.VisualStudio.TestTools.UnitTesting; 35 | 36 | namespace MonoTests.System.Net.Http.Headers 37 | { 38 | [TestClass] 39 | public class TransferCodingWithQualityHeaderValueTest 40 | { 41 | [TestMethod] 42 | public void Ctor () 43 | { 44 | var v = new TransferCodingWithQualityHeaderValue ("value"); 45 | Assert.AreEqual ("value", v.Value, "#1"); 46 | Assert.IsNull (v.Quality); 47 | } 48 | 49 | [TestMethod] 50 | public void Equals () 51 | { 52 | var tfhv = new TransferCodingWithQualityHeaderValue ("abc"); 53 | Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc"), "#1"); 54 | Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("AbC"), "#2"); 55 | Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("ab"), "#3"); 56 | Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("ab", 1), "#3"); 57 | 58 | tfhv = new TransferCodingWithQualityHeaderValue ("abc", 0.3); 59 | Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc", 0.3), "#4"); 60 | Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("AbC", 0.3), "#5"); 61 | Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc"), "#6"); 62 | 63 | var custom_param = new TransferCodingHeaderValue ("abc"); 64 | custom_param.Parameters.Add (new NameValueHeaderValue ("q", "0.3")); 65 | Assert.AreEqual (tfhv, custom_param, "#7"); 66 | } 67 | 68 | [TestMethod] 69 | public void Parse () 70 | { 71 | var res = TransferCodingWithQualityHeaderValue.Parse ("1.1"); 72 | Assert.AreEqual (0, res.Parameters.Count, "#1"); 73 | Assert.IsNull (res.Quality, "#1b"); 74 | Assert.AreEqual ("1.1", res.Value, "#1c"); 75 | Assert.AreEqual ("1.1", res.ToString (), "#1d"); 76 | 77 | res = TransferCodingWithQualityHeaderValue.Parse ("a ; b "); 78 | Assert.AreEqual (1, res.Parameters.Count, "#2"); 79 | Assert.IsNull (res.Quality, "#2b"); 80 | Assert.AreEqual ("a", res.Value, "#2c"); 81 | Assert.AreEqual ("a; b", res.ToString (), "#2d"); 82 | } 83 | 84 | [TestMethod] 85 | public void Parse_Invalid () 86 | { 87 | try { 88 | TransferCodingWithQualityHeaderValue.Parse (null); 89 | Assert.Fail ("#1"); 90 | } catch (FormatException) { 91 | } 92 | 93 | try { 94 | TransferCodingWithQualityHeaderValue.Parse (" "); 95 | Assert.Fail ("#2"); 96 | } catch (FormatException) { 97 | } 98 | } 99 | 100 | [TestMethod] 101 | public void Properties () 102 | { 103 | var v = new TransferCodingWithQualityHeaderValue ("value", 0.412); 104 | Assert.AreEqual ("value", v.Value, "#1"); 105 | Assert.AreEqual (0.412, v.Quality, "#2"); 106 | Assert.AreEqual ("0.412", v.Parameters.First ().Value, "#3"); 107 | 108 | v.Parameters.Add (new NameValueHeaderValue ("q", "0.2")); 109 | Assert.AreEqual (0.412, v.Quality, "#4"); 110 | 111 | v = new TransferCodingWithQualityHeaderValue ("value"); 112 | v.Parameters.Add (new NameValueHeaderValue ("q", "0.112")); 113 | Assert.AreEqual (0.112, v.Quality, "#5"); 114 | 115 | v = new TransferCodingWithQualityHeaderValue ("value"); 116 | v.Parameters.Add (new NameValueHeaderValue ("q", "test")); 117 | Assert.IsNull (v.Quality, "#6"); 118 | } 119 | 120 | [TestMethod] 121 | public void Properties_Invalid () 122 | { 123 | try { 124 | new TransferCodingWithQualityHeaderValue ("value", 4); 125 | Assert.Fail ("#1"); 126 | } catch (ArgumentOutOfRangeException) { 127 | } 128 | 129 | var v = new TransferCodingWithQualityHeaderValue ("value"); 130 | try { 131 | v.Quality = -1; 132 | Assert.Fail ("#2"); 133 | } catch (ArgumentOutOfRangeException) { 134 | } 135 | } 136 | } 137 | } -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http/ByteArrayContentTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ByteArrayContentTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Net.Http; 31 | using System.IO; 32 | using Microsoft.VisualStudio.TestTools.UnitTesting; 33 | 34 | namespace MonoTests.System.Net.Http 35 | { 36 | [TestClass] 37 | public class ByteArrayContentTest 38 | { 39 | [TestMethod] 40 | public void Ctor_Invalid () 41 | { 42 | try { 43 | new ByteArrayContent (null); 44 | Assert.Fail ("#1"); 45 | } catch (ArgumentNullException) { 46 | } 47 | 48 | try { 49 | new ByteArrayContent (new byte[0], -1, 2); 50 | Assert.Fail ("#2"); 51 | } catch (ArgumentOutOfRangeException) { 52 | } 53 | 54 | try { 55 | new ByteArrayContent (new byte[0], 11, 1); 56 | Assert.Fail ("#3"); 57 | } catch (ArgumentOutOfRangeException) { 58 | } 59 | 60 | try { 61 | new ByteArrayContent (new byte[10], 9, 5); 62 | Assert.Fail ("#4"); 63 | } catch (ArgumentOutOfRangeException) { 64 | } 65 | } 66 | 67 | [TestMethod] 68 | public void Ctor () 69 | { 70 | byte[] b = { 4, 6 }; 71 | 72 | using (var m = new ByteArrayContent (b)) { 73 | } 74 | } 75 | 76 | [TestMethod] 77 | public void CopyTo_Invalid () 78 | { 79 | var m = new MemoryStream (); 80 | 81 | var sc = new ByteArrayContent (new byte[0]); 82 | try { 83 | sc.CopyToAsync (null); 84 | Assert.Fail ("#1"); 85 | } catch (ArgumentNullException) { 86 | } 87 | } 88 | 89 | [TestMethod] 90 | public void CopyToAsync () 91 | { 92 | byte[] b = { 4, 2 }; 93 | 94 | var sc = new ByteArrayContent (b); 95 | 96 | var dest = new MemoryStream (); 97 | var task = sc.CopyToAsync (dest); 98 | Assert.IsTrue (task.Wait (500)); 99 | Assert.AreEqual (2, dest.Length, "#1"); 100 | } 101 | 102 | [TestMethod] 103 | public void LoadIntoBufferAsync () 104 | { 105 | byte[] b = { 4 }; 106 | 107 | var sc = new ByteArrayContent (b); 108 | var t = sc.LoadIntoBufferAsync (400); 109 | Assert.IsTrue (t.Wait (500)); 110 | } 111 | 112 | [TestMethod] 113 | public void ReadAsByteArrayAsync () 114 | { 115 | byte[] b = { 4, 55 }; 116 | 117 | var sc = new ByteArrayContent (b, 1, 1); 118 | var res = sc.ReadAsByteArrayAsync ().Result; 119 | Assert.AreEqual (1, res.Length, "#1"); 120 | Assert.AreEqual (55, res[0], "#2"); 121 | 122 | sc = new ByteArrayContent (b); 123 | res = sc.ReadAsByteArrayAsync ().Result; 124 | Assert.AreEqual (2, res.Length, "#10"); 125 | Assert.AreEqual (55, res[1], "#11"); 126 | } 127 | 128 | [TestMethod] 129 | public void ReadAsStringAsync () 130 | { 131 | byte[] b = { 77, 55 }; 132 | 133 | var sc = new ByteArrayContent (b); 134 | var res = sc.ReadAsStringAsync ().Result; 135 | Assert.AreEqual ("M7", res, "#1"); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http/DelegatingHandlerTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // DelegatingHandlerTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using NUnit.Framework; 31 | using System.Net.Http; 32 | using System.IO; 33 | using System.Threading.Tasks; 34 | 35 | namespace MonoTests.System.Net.Http 36 | { 37 | [TestFixture] 38 | public class DelegatingHandlerTest 39 | { 40 | class DefaultHandler : DelegatingHandler 41 | { 42 | } 43 | 44 | 45 | [Test] 46 | public void DisposeTest () 47 | { 48 | var handler = new DefaultHandler (); 49 | handler.Dispose (); 50 | } 51 | 52 | [Test] 53 | public void InnerHandler_Invalid () 54 | { 55 | var handler = new DefaultHandler (); 56 | try { 57 | handler.InnerHandler = null; 58 | Assert.Fail ("#1"); 59 | } catch (ArgumentNullException) { 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http/FormUrlEncodedContentTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // FormUrlEncodedContentTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Net.Http; 31 | using System.IO; 32 | using System.Collections.Generic; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http 36 | { 37 | [TestClass] 38 | public class FormUrlEncodedContentTest 39 | { 40 | [TestMethod] 41 | public void Ctor_Invalid () 42 | { 43 | try { 44 | new FormUrlEncodedContent (null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentNullException) { 47 | } 48 | } 49 | 50 | [TestMethod] 51 | public void Ctor () 52 | { 53 | var s = new List> () { 54 | new KeyValuePair ("key", "44"), 55 | new KeyValuePair ("key 2", "&+/Ž@:=") 56 | }; 57 | 58 | using (var m = new FormUrlEncodedContent (s)) { 59 | Assert.AreEqual ("application/x-www-form-urlencoded", m.Headers.ContentType.MediaType, "#1"); 60 | Assert.AreEqual (37, m.Headers.ContentLength, "#2"); 61 | Assert.AreEqual ("key=44&key+2=%26%2B%2F%C5%BD%40%3A%3D", m.ReadAsStringAsync ().Result, "#3"); 62 | } 63 | 64 | s = new List> (); 65 | using (var m = new FormUrlEncodedContent (s)) { 66 | Assert.AreEqual ("application/x-www-form-urlencoded", m.Headers.ContentType.MediaType, "#11"); 67 | Assert.AreEqual (0, m.Headers.ContentLength, "#12"); 68 | Assert.AreEqual ("", m.ReadAsStringAsync ().Result, "#13"); 69 | } 70 | 71 | s = new List> () { 72 | new KeyValuePair ( "key", ""), 73 | new KeyValuePair ( "key+ 2", null) 74 | }; 75 | 76 | using (var m = new FormUrlEncodedContent (s)) { 77 | Assert.AreEqual ("application/x-www-form-urlencoded", m.Headers.ContentType.MediaType, "#21"); 78 | Assert.AreEqual (14, m.Headers.ContentLength, "#22"); 79 | Assert.AreEqual ("key=&key%2B+2=", m.ReadAsStringAsync ().Result, "#23"); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpClientHandlerTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http; 33 | using System.Net; 34 | using Microsoft.VisualStudio.TestTools.UnitTesting; 35 | 36 | namespace MonoTests.System.Net.Http 37 | { 38 | extern alias tpl; 39 | using AggregateException = tpl::System.AggregateException; 40 | 41 | [TestClass] 42 | public class HttpClientHandlerTest 43 | { 44 | class Proxy : IWebProxy 45 | { 46 | public ICredentials Credentials { 47 | get { 48 | throw new NotImplementedException (); 49 | } 50 | set { 51 | throw new NotImplementedException (); 52 | } 53 | } 54 | 55 | public Uri GetProxy (Uri destination) 56 | { 57 | throw new NotImplementedException (); 58 | } 59 | 60 | public bool IsBypassed (Uri host) 61 | { 62 | throw new NotImplementedException (); 63 | } 64 | } 65 | 66 | [TestMethod] 67 | public void Properties_Defaults () 68 | { 69 | var h = new HttpClientHandler (); 70 | Assert.IsTrue (h.AllowAutoRedirect, "#1"); 71 | Assert.AreEqual (DecompressionMethods.None, h.AutomaticDecompression, "#2"); 72 | Assert.AreEqual (0, h.CookieContainer.Count, "#3"); 73 | Assert.AreEqual (4096, h.CookieContainer.MaxCookieSize, "#3b"); 74 | Assert.AreEqual (null, h.Credentials, "#4"); 75 | Assert.AreEqual (50, h.MaxAutomaticRedirections, "#5"); 76 | Assert.AreEqual (int.MaxValue, h.MaxRequestContentBufferSize, "#6"); 77 | Assert.IsFalse (h.PreAuthenticate, "#7"); 78 | Assert.IsNull (h.Proxy, "#8"); 79 | Assert.IsTrue (h.SupportsAutomaticDecompression, "#9"); 80 | Assert.IsTrue (h.SupportsProxy, "#10"); 81 | Assert.IsTrue (h.SupportsRedirectConfiguration, "#11"); 82 | Assert.IsTrue (h.UseCookies, "#12"); 83 | Assert.IsFalse (h.UseDefaultCredentials, "#13"); 84 | Assert.IsTrue (h.UseProxy, "#14"); 85 | Assert.AreEqual (ClientCertificateOption.Manual, h.ClientCertificateOptions, "#15"); 86 | } 87 | 88 | [TestMethod] 89 | public void Properties_Invalid () 90 | { 91 | var h = new HttpClientHandler (); 92 | try { 93 | h.MaxAutomaticRedirections = 0; 94 | Assert.Fail ("#1"); 95 | } catch (ArgumentOutOfRangeException) { 96 | } 97 | 98 | try { 99 | h.MaxRequestContentBufferSize = -1; 100 | Assert.Fail ("#2"); 101 | } catch (ArgumentOutOfRangeException) { 102 | } 103 | 104 | h.UseProxy = false; 105 | try { 106 | h.Proxy = new Proxy (); 107 | Assert.Fail ("#3"); 108 | } catch (InvalidOperationException) { 109 | } 110 | } 111 | 112 | [TestMethod] 113 | public void Properties_AfterClientCreation () 114 | { 115 | var h = new HttpClientHandler (); 116 | h.AllowAutoRedirect = true; 117 | 118 | // We may modify properties after creating the HttpClient. 119 | using (var c = new HttpClient (h, true)) { 120 | h.AllowAutoRedirect = false; 121 | } 122 | } 123 | 124 | [TestMethod] 125 | public void Disposed () 126 | { 127 | var h = new HttpClientHandler (); 128 | h.Dispose (); 129 | var c = new HttpClient (h); 130 | try { 131 | c.GetAsync ("http://google.com").Wait (); 132 | Assert.Fail ("#1"); 133 | } catch (AggregateException e) { 134 | Assert.IsTrue (e.InnerException is ObjectDisposedException, "#2"); 135 | } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http/HttpMethodTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // HttpMethodTest.cs 3 | // 4 | // Authors: 5 | // Marek Safar 6 | // 7 | // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | using System; 30 | using System.Collections; 31 | using System.Collections.Generic; 32 | using System.Net.Http; 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | namespace MonoTests.System.Net.Http 36 | { 37 | [TestClass] 38 | public class HttpMethodTest 39 | { 40 | [TestMethod] 41 | public void Ctor_Invalid () 42 | { 43 | try { 44 | new HttpMethod (null); 45 | Assert.Fail ("#1"); 46 | } catch (ArgumentException) { 47 | } 48 | 49 | try { 50 | new HttpMethod (""); 51 | Assert.Fail ("#2"); 52 | } catch (ArgumentException) { 53 | } 54 | 55 | try { 56 | new HttpMethod (" "); 57 | Assert.Fail ("#3"); 58 | } catch (FormatException) { 59 | } 60 | } 61 | 62 | [TestMethod] 63 | public void Ctor () 64 | { 65 | var m = new HttpMethod ("get"); 66 | Assert.AreEqual ("get", m.Method, "#1"); 67 | } 68 | 69 | [TestMethod] 70 | public void Equal () 71 | { 72 | var m = new HttpMethod ("get"); 73 | Assert.AreEqual (m, new HttpMethod ("get"), "#1"); 74 | Assert.AreEqual (m, HttpMethod.Get, "#2"); 75 | Assert.AreNotEqual (m, null, "#3"); 76 | } 77 | 78 | [TestMethod] 79 | public void StaticProperties () 80 | { 81 | Assert.AreEqual ("DELETE", HttpMethod.Delete.Method, "#1"); 82 | Assert.AreEqual ("GET", HttpMethod.Get.Method, "#2"); 83 | Assert.AreEqual ("HEAD", HttpMethod.Head.Method, "#3"); 84 | Assert.AreEqual ("OPTIONS", HttpMethod.Options.Method, "#4"); 85 | Assert.AreEqual ("POST", HttpMethod.Post.Method, "#5"); 86 | Assert.AreEqual ("PUT", HttpMethod.Put.Method, "#6"); 87 | Assert.AreEqual ("TRACE", HttpMethod.Trace.Method, "#7"); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /System.Net.Http/Test/System.Net.Http/StringContentTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-httpclient35/9ab946aebe82cf57b8d36906e7f47305afab99fe/System.Net.Http/Test/System.Net.Http/StringContentTest.cs -------------------------------------------------------------------------------- /System.Net.Http/monotouch_System.Net.Http.dll.sources: -------------------------------------------------------------------------------- 1 | ../../build/common/Consts.cs 2 | Assembly/AssemblyInfo.cs 3 | System.Net.Http/ByteArrayContent.cs 4 | System.Net.Http/ClientCertificateOption.cs 5 | System.Net.Http/DelegatingHandler.cs 6 | System.Net.Http/FormUrlEncodedContent.cs 7 | System.Net.Http/HttpClient.cs 8 | System.Net.Http/HttpClientHandler.cs 9 | System.Net.Http/HttpCompletionOption.cs 10 | System.Net.Http/HttpContent.cs 11 | System.Net.Http/HttpMessageHandler.cs 12 | System.Net.Http/HttpMessageInvoker.cs 13 | System.Net.Http/HttpMethod.cs 14 | System.Net.Http/HttpRequestException.cs 15 | System.Net.Http/HttpRequestMessage.cs 16 | System.Net.Http/HttpResponseMessage.cs 17 | System.Net.Http/MessageProcessingHandler.cs 18 | System.Net.Http/MultipartContent.cs 19 | System.Net.Http/MultipartFormDataContent.cs 20 | System.Net.Http/StreamContent.cs 21 | System.Net.Http/StringContent.cs 22 | System.Net.Http.Headers/AuthenticationHeaderValue.cs 23 | System.Net.Http.Headers/CacheControlHeaderValue.cs 24 | System.Net.Http.Headers/CollectionExtensions.cs 25 | System.Net.Http.Headers/CollectionParser.cs 26 | System.Net.Http.Headers/ContentDispositionHeaderValue.cs 27 | System.Net.Http.Headers/ContentRangeHeaderValue.cs 28 | System.Net.Http.Headers/EntityTagHeaderValue.cs 29 | System.Net.Http.Headers/HashCodeCalculator.cs 30 | System.Net.Http.Headers/HeaderInfo.cs 31 | System.Net.Http.Headers/HttpContentHeaders.cs 32 | System.Net.Http.Headers/HttpHeaderKind.cs 33 | System.Net.Http.Headers/HttpHeaders.cs 34 | System.Net.Http.Headers/HttpHeaderValueCollection.cs 35 | System.Net.Http.Headers/HttpRequestHeaders.cs 36 | System.Net.Http.Headers/HttpResponseHeaders.cs 37 | System.Net.Http.Headers/Lexer.cs 38 | System.Net.Http.Headers/MediaTypeHeaderValue.cs 39 | System.Net.Http.Headers/MediaTypeWithQualityHeaderValue.cs 40 | System.Net.Http.Headers/NameValueHeaderValue.cs 41 | System.Net.Http.Headers/NameValueWithParametersHeaderValue.cs 42 | System.Net.Http.Headers/Parser.cs 43 | System.Net.Http.Headers/ProductHeaderValue.cs 44 | System.Net.Http.Headers/ProductInfoHeaderValue.cs 45 | System.Net.Http.Headers/QualityValue.cs 46 | System.Net.Http.Headers/RangeConditionHeaderValue.cs 47 | System.Net.Http.Headers/RangeHeaderValue.cs 48 | System.Net.Http.Headers/RangeItemHeaderValue.cs 49 | System.Net.Http.Headers/RetryConditionHeaderValue.cs 50 | System.Net.Http.Headers/StringWithQualityHeaderValue.cs 51 | System.Net.Http.Headers/TransferCodingHeaderValue.cs 52 | System.Net.Http.Headers/TransferCodingWithQualityHeaderValue.cs 53 | System.Net.Http.Headers/ViaHeaderValue.cs 54 | System.Net.Http.Headers/WarningHeaderValue.cs -------------------------------------------------------------------------------- /System.Net.Http/packages.System.Net.Http-net_4_5.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /System.Net.Http/packages.System.Net.Http-tests-net_4_5.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /build/KeyReporting.targets: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | This project references a strong name key that is missing on this computer. Run 'sn -k {0}' to generate the file. 13 | 14 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /build/build.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [switch]$Debug, 3 | [string]$VisualStudioVersion = "12.0", 4 | [switch]$SkipKeyCheck 5 | ) 6 | 7 | # build the solution 8 | $SolutionPath = "..\System.Net.Http\System.Net.Http-net_4_5.sln" 9 | 10 | # make sure the script was run from the expected path 11 | if (!(Test-Path $SolutionPath)) { 12 | $host.ui.WriteErrorLine('The script was run from an invalid working directory.') 13 | exit 1 14 | } 15 | 16 | . .\version.ps1 17 | 18 | If ($Debug) { 19 | $BuildConfig = 'Debug' 20 | } Else { 21 | $BuildConfig = 'Release' 22 | } 23 | 24 | If ($Version.Contains('-')) { 25 | $KeyConfiguration = 'Dev' 26 | } Else { 27 | $KeyConfiguration = 'Final' 28 | } 29 | 30 | # build the main project 31 | $msbuild = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" 32 | 33 | &$msbuild '/nologo' '/m' '/nr:false' '/t:rebuild' "/p:Configuration=$BuildConfig" "/p:VisualStudioVersion=$VisualStudioVersion" "/p:KeyConfiguration=$KeyConfiguration" $SolutionPath 34 | if ($LASTEXITCODE -ne 0) { 35 | $host.ui.WriteErrorLine('Build failed, aborting!') 36 | exit $p.ExitCode 37 | } 38 | 39 | # By default, do not create a NuGet package unless the expected strong name key files were used 40 | if (-not $SkipKeyCheck) { 41 | . .\keys.ps1 42 | 43 | foreach ($pair in $Keys.GetEnumerator()) { 44 | $assembly = Resolve-FullPath -Path "..\System.Net.Http\bin\$BuildConfig\System.Net.Http.dll" 45 | # Run the actual check in a separate process or the current process will keep the assembly file locked 46 | powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'" 47 | if ($LASTEXITCODE -ne 0) { 48 | Exit $p.ExitCode 49 | } 50 | } 51 | } 52 | 53 | if (-not (Test-Path 'nuget')) { 54 | mkdir "nuget" 55 | } 56 | 57 | ..\System.Net.Http\.nuget\NuGet.exe 'pack' '..\System.Net.Http\Rackspace.HttpClient35.nuspec' '-OutputDirectory' 'nuget' '-Prop' "Configuration=$BuildConfig" '-Version' "$Version" '-Symbols' 58 | -------------------------------------------------------------------------------- /build/check-key.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [string]$Assembly, 3 | [string]$ExpectedKey, 4 | [string]$Build = $null 5 | ) 6 | 7 | function Get-PublicKeyToken() { 8 | param([string]$assembly = $null) 9 | if ($assembly) { 10 | $bytes = $null 11 | $bytes = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($assembly).GetName().GetPublicKeyToken() 12 | if ($bytes) { 13 | $key = "" 14 | for ($i=0; $i -lt $bytes.Length; $i++) { 15 | $key += "{0:x2}" -f $bytes[$i] 16 | } 17 | 18 | $key 19 | } 20 | } 21 | } 22 | 23 | if (-not $Build) { 24 | $Build = $Assembly 25 | } 26 | 27 | $actual = Get-PublicKeyToken -assembly $Assembly 28 | if ($actual -ne $ExpectedKey) { 29 | $host.ui.WriteErrorLine("Invalid publicKeyToken for '$Build'; expected '$ExpectedKey' but found '$actual'") 30 | exit 1 31 | } 32 | -------------------------------------------------------------------------------- /build/keys.ps1: -------------------------------------------------------------------------------- 1 | # Note: these values may only change during major release 2 | 3 | If ($Version.Contains('-')) { 4 | 5 | # Use the development keys 6 | $Keys = @{ 7 | 'net35' = 'c2814533e73a79ce' 8 | } 9 | 10 | } Else { 11 | 12 | # Use the final release keys 13 | $Keys = @{ 14 | 'net35' = '9f4d6a8a33d00520' 15 | } 16 | 17 | } 18 | 19 | function Resolve-FullPath() { 20 | param([string]$Path) 21 | [System.IO.Path]::GetFullPath((Join-Path (pwd) $Path)) 22 | } 23 | -------------------------------------------------------------------------------- /build/keys/HttpClient35.dev.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-httpclient35/9ab946aebe82cf57b8d36906e7f47305afab99fe/build/keys/HttpClient35.dev.snk -------------------------------------------------------------------------------- /build/keys/HttpClient35.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-httpclient35/9ab946aebe82cf57b8d36906e7f47305afab99fe/build/keys/HttpClient35.snk -------------------------------------------------------------------------------- /build/push.ps1: -------------------------------------------------------------------------------- 1 | . .\version.ps1 2 | 3 | If ($Version.EndsWith('-dev')) { 4 | $host.ui.WriteErrorLine("Cannot push development version '$Version' to NuGet.") 5 | Exit 1 6 | } 7 | 8 | ..\System.Net.Http\.nuget\NuGet.exe 'push' ".\nuget\Rackspace.HttpClient35.$Version.nupkg" 9 | -------------------------------------------------------------------------------- /build/version.ps1: -------------------------------------------------------------------------------- 1 | $Version = "1.0.0-dev" 2 | --------------------------------------------------------------------------------