├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── HttpClient.sln
├── LICENSE.txt
├── NuGet.Config
├── README.md
├── build.cmd
├── build.sh
├── global.json
├── makefile.shade
├── samples
└── TestClient
│ ├── App.config
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── TestClient.csproj
│ ├── TestClient.kproj
│ └── project.json
├── src
└── Microsoft.Net.Http.Client
│ ├── ApmStream.cs
│ ├── ApmStreamWrapper.cs
│ ├── BufferedReadStream.cs
│ ├── ChunkedReadStream.cs
│ ├── ContentLengthReadStream.cs
│ ├── HttpConnection.cs
│ ├── HttpConnectionResponseContent.cs
│ ├── ManagedHandler.cs
│ ├── Microsoft.Net.Http.Client.csproj
│ ├── Microsoft.Net.Http.Client.kproj
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ProxyMode.cs
│ ├── RedirectMode.cs
│ ├── RequestExtensions.cs
│ └── project.json
└── test
└── Microsoft.Net.Http.Client.FunctionalTests
├── HelloWorldTests.cs
├── Microsoft.Net.Http.Client.FunctionalTests.csproj
├── Microsoft.Net.Http.Client.FunctionalTests.kproj
├── Properties
└── AssemblyInfo.cs
├── RedirectTests.cs
├── Utilities.cs
├── packages.config
└── project.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.doc diff=astextplain
2 | *.DOC diff=astextplain
3 | *.docx diff=astextplain
4 | *.DOCX diff=astextplain
5 | *.dot diff=astextplain
6 | *.DOT diff=astextplain
7 | *.pdf diff=astextplain
8 | *.PDF diff=astextplain
9 | *.rtf diff=astextplain
10 | *.RTF diff=astextplain
11 |
12 | *.jpg binary
13 | *.png binary
14 | *.gif binary
15 |
16 | *.cs text=auto diff=csharp
17 | *.vb text=auto
18 | *.resx text=auto
19 | *.c text=auto
20 | *.cpp text=auto
21 | *.cxx text=auto
22 | *.h text=auto
23 | *.hxx text=auto
24 | *.py text=auto
25 | *.rb text=auto
26 | *.java text=auto
27 | *.html text=auto
28 | *.htm text=auto
29 | *.css text=auto
30 | *.scss text=auto
31 | *.sass text=auto
32 | *.less text=auto
33 | *.js text=auto
34 | *.lisp text=auto
35 | *.clj text=auto
36 | *.sql text=auto
37 | *.php text=auto
38 | *.lua text=auto
39 | *.m text=auto
40 | *.asm text=auto
41 | *.erl text=auto
42 | *.fs text=auto
43 | *.fsx text=auto
44 | *.hs text=auto
45 |
46 | *.csproj text=auto
47 | *.vbproj text=auto
48 | *.fsproj text=auto
49 | *.dbproj text=auto
50 | *.sln text=auto eol=crlf
51 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Oo]bj/
2 | [Bb]in/
3 | TestResults/
4 | .nuget/
5 | *.sln.ide/
6 | _ReSharper.*/
7 | packages/
8 | artifacts/
9 | PublishProfiles/
10 | *.user
11 | *.suo
12 | *.cache
13 | *.docstates
14 | _ReSharper.*
15 | nuget.exe
16 | *net45.csproj
17 | *net451.csproj
18 | *k10.csproj
19 | *.psess
20 | *.vsp
21 | *.pidb
22 | *.userprefs
23 | *DS_Store
24 | *.ncrunchsolution
25 | *.*sdf
26 | *.ipch
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ======
3 |
4 | Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo.
5 |
--------------------------------------------------------------------------------
/HttpClient.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.22228.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Net.Http.Client", "src\Microsoft.Net.Http.Client\Microsoft.Net.Http.Client.kproj", "{9057D304-79FB-4B91-8C28-B7AB22ED20FE}"
7 | EndProject
8 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Net.Http.Client.FunctionalTests", "test\Microsoft.Net.Http.Client.FunctionalTests\Microsoft.Net.Http.Client.FunctionalTests.kproj", "{010C9E4F-A496-43B7-BFFC-5E6E2F64552E}"
9 | EndProject
10 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestClient", "samples\TestClient\TestClient.kproj", "{9BC253B1-FEB5-4475-ACA6-EAECB4FBFE32}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B0A0E824-39C6-469D-9E28-C8731D5DF69E}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{330EDBBD-F18B-4136-A492-30AFC06BB68B}"
15 | ProjectSection(SolutionItems) = preProject
16 | global.json = global.json
17 | EndProjectSection
18 | EndProject
19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{34DC8DD8-7C39-415D-98E9-E11F12FD735F}"
20 | EndProject
21 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{44812035-7134-4877-BD8C-F011171FF21D}"
22 | EndProject
23 | Global
24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
25 | Debug|Any CPU = Debug|Any CPU
26 | Release|Any CPU = Release|Any CPU
27 | EndGlobalSection
28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
29 | {9057D304-79FB-4B91-8C28-B7AB22ED20FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {9057D304-79FB-4B91-8C28-B7AB22ED20FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {9057D304-79FB-4B91-8C28-B7AB22ED20FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {9057D304-79FB-4B91-8C28-B7AB22ED20FE}.Release|Any CPU.Build.0 = Release|Any CPU
33 | {010C9E4F-A496-43B7-BFFC-5E6E2F64552E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {010C9E4F-A496-43B7-BFFC-5E6E2F64552E}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {010C9E4F-A496-43B7-BFFC-5E6E2F64552E}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {010C9E4F-A496-43B7-BFFC-5E6E2F64552E}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {9BC253B1-FEB5-4475-ACA6-EAECB4FBFE32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38 | {9BC253B1-FEB5-4475-ACA6-EAECB4FBFE32}.Debug|Any CPU.Build.0 = Debug|Any CPU
39 | {9BC253B1-FEB5-4475-ACA6-EAECB4FBFE32}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {9BC253B1-FEB5-4475-ACA6-EAECB4FBFE32}.Release|Any CPU.Build.0 = Release|Any CPU
41 | EndGlobalSection
42 | GlobalSection(SolutionProperties) = preSolution
43 | HideSolutionNode = FALSE
44 | EndGlobalSection
45 | GlobalSection(NestedProjects) = preSolution
46 | {9057D304-79FB-4B91-8C28-B7AB22ED20FE} = {B0A0E824-39C6-469D-9E28-C8731D5DF69E}
47 | {010C9E4F-A496-43B7-BFFC-5E6E2F64552E} = {44812035-7134-4877-BD8C-F011171FF21D}
48 | {9BC253B1-FEB5-4475-ACA6-EAECB4FBFE32} = {34DC8DD8-7C39-415D-98E9-E11F12FD735F}
49 | EndGlobalSection
50 | EndGlobal
51 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | these files except in compliance with the License. You may obtain a copy of the
5 | License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software distributed
10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | specific language governing permissions and limitations under the License.
13 |
--------------------------------------------------------------------------------
/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | HttpClient
2 | ===
3 |
4 | Fully managed HttpMessageHandler implementation based on sockets.
5 |
6 |
7 | This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo.
8 |
9 |
--------------------------------------------------------------------------------
/build.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | cd %~dp0
3 |
4 | SETLOCAL
5 | SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe
6 |
7 | IF EXIST %CACHED_NUGET% goto copynuget
8 | echo Downloading latest version of NuGet.exe...
9 | IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
10 | @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"
11 |
12 | :copynuget
13 | IF EXIST .nuget\nuget.exe goto restore
14 | md .nuget
15 | copy %CACHED_NUGET% .nuget\nuget.exe > nul
16 |
17 | :restore
18 | IF EXIST packages\KoreBuild goto run
19 | .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
20 | .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion
21 |
22 | IF "%SKIP_KRE_INSTALL%"=="1" goto run
23 | CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86
24 | CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86
25 |
26 | :run
27 | CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86
28 | packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
29 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if test `uname` = Darwin; then
4 | cachedir=~/Library/Caches/KBuild
5 | else
6 | if x$XDG_DATA_HOME = x; then
7 | cachedir=$HOME/.local/share
8 | else
9 | cachedir=$XDG_DATA_HOME;
10 | fi
11 | fi
12 | mkdir -p $cachedir
13 |
14 | url=https://www.nuget.org/nuget.exe
15 |
16 | if test ! -f $cachedir/nuget.exe; then
17 | wget -o $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null
18 | fi
19 |
20 | if test ! -e .nuget; then
21 | mkdir .nuget
22 | cp $cachedir/nuget.exe .nuget
23 | fi
24 |
25 | if test ! -d packages/KoreBuild; then
26 | mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
27 | mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion
28 | fi
29 |
30 | KRE_VERSION=$(mono .nuget/nuget.exe install KRE-mono45-x86 -pre -o ~/.kre/packages | head -1 | sed "s/.*KRE-mono45-x86 \([^']*\).*/\1/")
31 | KRE_BIN=~/.kre/packages/KRE-mono45-x86.$KRE_VERSION/bin
32 |
33 | chmod +x $KRE_BIN/k
34 | chmod +x $KRE_BIN/klr
35 | chmod +x $KRE_BIN/kpm
36 | chmod +x $KRE_BIN/k-build
37 |
38 | export PATH=$KRE_BIN:$PATH
39 |
40 | mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sources": ["src"]
3 | }
--------------------------------------------------------------------------------
/makefile.shade:
--------------------------------------------------------------------------------
1 |
2 | var VERSION='1.0'
3 | var FULL_VERSION='0.1'
4 | var AUTHORS='Microsoft'
5 |
6 | use-standard-lifecycle
7 | k-standard-goals
8 |
--------------------------------------------------------------------------------
/samples/TestClient/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/samples/TestClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Http;
3 | using Microsoft.Net.Http.Client;
4 |
5 | namespace TestClient
6 | {
7 | class Program
8 | {
9 | public static void Main(string[] args)
10 | {
11 | // System.Diagnostics.Debugger.Launch();
12 | HttpClient client = new HttpClient(new ManagedHandler()
13 | {
14 | // ProxyAddress = new Uri("http://itgproxy:80")
15 | });
16 |
17 | var response = client.GetAsync(
18 | // "https://www.myget.org/f/aspnetwebstacknightly/"
19 | "https://packages.nuget.org/v1/Package/Download/EntityFramework/4.1.10331.0"
20 | ).Result;
21 | Console.WriteLine(response);
22 | // Console.WriteLine(response.Content.ReadAsStringAsync().Result);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/samples/TestClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("TestClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("TestClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dc4c9e7d-020e-4031-9e7d-3dcfb042f2b8")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/samples/TestClient/TestClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {66DB9DF3-F8EF-4447-B0A6-C3512D73544E}
8 | Exe
9 | Properties
10 | TestClient
11 | TestClient
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
59 |
--------------------------------------------------------------------------------
/samples/TestClient/TestClient.kproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 12.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 |
9 | 9bc253b1-feb5-4475-aca6-eaecb4fbfe32
10 | Library
11 |
12 |
13 | ConsoleDebugger
14 |
15 |
16 | WebDebugger
17 |
18 |
19 |
20 |
21 |
22 |
23 | TestClient
24 |
25 |
26 | TestClient
27 |
28 |
29 | 2.0
30 |
31 |
32 |
--------------------------------------------------------------------------------
/samples/TestClient/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "Microsoft.Net.Http.Client": "1.0.0-*"
4 | },
5 | "frameworks": {
6 | "net45": {
7 | "frameworkAssemblies": {
8 | "System.Net.Http": ""
9 | }
10 | },
11 | "aspnet50": {
12 | "frameworkAssemblies": {
13 | "System.Net.Http": ""
14 | }
15 | },
16 | "aspnetcore50": {
17 | "dependencies": {
18 | "System.Console": "4.0.0-beta-*",
19 | "System.Net.Http": "4.0.0-beta-*",
20 | "System.Runtime": "4.0.20-beta-*"
21 | }
22 | }
23 | },
24 | "webroot": null
25 | }
--------------------------------------------------------------------------------
/src/Microsoft.Net.Http.Client/ApmStream.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Microsoft.Net.Http.Client
5 | {
6 | ///
7 | /// Summary description for ApmStream
8 | ///
9 | public abstract class ApmStream : Stream
10 | {
11 | #if !NET45
12 | public abstract IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, Object state);
13 | #endif
14 |
15 | #if !NET45
16 | public abstract int EndRead(IAsyncResult asyncResult);
17 | #endif
18 |
19 | #if !NET45
20 | public abstract IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, Object state);
21 | #endif
22 |
23 | #if !NET45
24 | public abstract void EndWrite(IAsyncResult asyncResult);
25 | #endif
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Microsoft.Net.Http.Client/ApmStreamWrapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.Net.Http.Client
7 | {
8 | public class ApmStreamWrapper : ApmStream
9 | {
10 | private Stream _innerStream;
11 |
12 | public ApmStreamWrapper(Stream innerStream)
13 | {
14 | _innerStream = innerStream;
15 | }
16 |
17 | public override bool CanRead
18 | {
19 | get
20 | {
21 | return _innerStream.CanRead;
22 | }
23 | }
24 |
25 | public override bool CanSeek
26 | {
27 | get
28 | {
29 | return _innerStream.CanSeek;
30 | }
31 | }
32 |
33 | public override bool CanWrite
34 | {
35 | get
36 | {
37 | return _innerStream.CanWrite;
38 | }
39 | }
40 |
41 | public override bool CanTimeout
42 | {
43 | get
44 | {
45 | return _innerStream.CanTimeout;
46 | }
47 | }
48 |
49 | public override int ReadTimeout
50 | {
51 | get
52 | {
53 | return _innerStream.ReadTimeout;
54 | }
55 |
56 | set
57 | {
58 | _innerStream.ReadTimeout = value;
59 | }
60 | }
61 |
62 | public override int WriteTimeout
63 | {
64 | get
65 | {
66 | return _innerStream.WriteTimeout;
67 | }
68 |
69 | set
70 | {
71 | _innerStream.WriteTimeout = value;
72 | }
73 | }
74 |
75 | public override long Length
76 | {
77 | get
78 | {
79 | return _innerStream.Length;
80 | }
81 | }
82 |
83 | public override long Position
84 | {
85 | get
86 | {
87 | return _innerStream.Position;
88 | }
89 |
90 | set
91 | {
92 | _innerStream.Position = value;
93 | }
94 | }
95 |
96 | public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
97 | {
98 | #if ASPNETCORE50
99 | TaskCompletionSource tcs = new TaskCompletionSource(state);
100 | InternalReadAsync(buffer, offset, size, callback, tcs);
101 | return tcs.Task;
102 | #else
103 | return _innerStream.BeginRead(buffer, offset, size, callback, state);
104 | #endif
105 | }
106 |
107 | #if ASPNETCORE50
108 | private async void InternalReadAsync(byte[] buffer, int offset, int size, AsyncCallback callback, TaskCompletionSource tcs)
109 | {
110 | try
111 | {
112 | int read = await _innerStream.ReadAsync(buffer, offset, size);
113 | tcs.TrySetResult(read);
114 | }
115 | catch (Exception ex)
116 | {
117 | tcs.TrySetException(ex);
118 | }
119 |
120 | try
121 | {
122 | callback(tcs.Task);
123 | }
124 | catch (Exception)
125 | {
126 | }
127 | }
128 | #endif
129 |
130 | public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
131 | {
132 | #if ASPNETCORE50
133 | TaskCompletionSource