Skip to content

Commit

Permalink
Added a proxy middleware that passes requests to specified remote ser…
Browse files Browse the repository at this point in the history
…vers
  • Loading branch information
mikaelm12 committed Aug 6, 2015
1 parent a9f7821 commit a416b4b
Show file tree
Hide file tree
Showing 22 changed files with 743 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

*.jpg binary
*.png binary
*.gif binary

*.cs text=auto diff=csharp
*.vb text=auto
*.resx text=auto
*.c text=auto
*.cpp text=auto
*.cxx text=auto
*.h text=auto
*.hxx text=auto
*.py text=auto
*.rb text=auto
*.java text=auto
*.html text=auto
*.htm text=auto
*.css text=auto
*.scss text=auto
*.sass text=auto
*.less text=auto
*.js text=auto
*.lisp text=auto
*.clj text=auto
*.sql text=auto
*.php text=auto
*.lua text=auto
*.m text=auto
*.asm text=auto
*.erl text=auto
*.fs text=auto
*.fsx text=auto
*.hs text=auto

*.csproj text=auto
*.vbproj text=auto
*.fsproj text=auto
*.dbproj text=auto
*.sln text=auto eol=crlf
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[Oo]bj/
[Bb]in/
TestResults/
.nuget/
*.sln.ide/
_ReSharper.*/
packages/
artifacts/
PublishProfiles/
*.user
*.suo
*.cache
*.docstates
_ReSharper.*
nuget.exe
project.lock.json
*net45.csproj
*net451.csproj
*k10.csproj
*.psess
*.vsp
*.pidb
*.userprefs
*DS_Store
*.ncrunchsolution
*.*sdf
*.ipch
.vs/
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: csharp
sudo: false
script:
- ./build.sh --quiet verify
7 changes: 7 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
</configuration>
50 changes: 50 additions & 0 deletions Proxy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{339381AB-344C-47CD-BA9D-30310AEB8DFF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4579A551-D026-4701-94A2-E1818AD24432}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{21867C30-38A2-44B0-AF3C-6C49F069734F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B7063BC9-D86B-49CE-90AD-7743788F7FC0}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Proxy.Test", "test\Microsoft.AspNet.Proxy.Test\Microsoft.AspNet.Proxy.Test.xproj", "{B2AF7BAB-E974-42A8-93A2-6CFE10BD8919}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Proxy", "src\Microsoft.AspNet.Proxy\Microsoft.AspNet.Proxy.xproj", "{4DAA0A9D-056E-4429-8C04-83715A93B56E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Proxy.Samples", "samples\Microsoft.AspNet.Proxy.Samples\Microsoft.AspNet.Proxy.Samples.xproj", "{038E3540-8594-4DC5-965D-7F24C56E1CF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B2AF7BAB-E974-42A8-93A2-6CFE10BD8919}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2AF7BAB-E974-42A8-93A2-6CFE10BD8919}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2AF7BAB-E974-42A8-93A2-6CFE10BD8919}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2AF7BAB-E974-42A8-93A2-6CFE10BD8919}.Release|Any CPU.Build.0 = Release|Any CPU
{4DAA0A9D-056E-4429-8C04-83715A93B56E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4DAA0A9D-056E-4429-8C04-83715A93B56E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DAA0A9D-056E-4429-8C04-83715A93B56E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DAA0A9D-056E-4429-8C04-83715A93B56E}.Release|Any CPU.Build.0 = Release|Any CPU
{038E3540-8594-4DC5-965D-7F24C56E1CF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{038E3540-8594-4DC5-965D-7F24C56E1CF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{038E3540-8594-4DC5-965D-7F24C56E1CF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{038E3540-8594-4DC5-965D-7F24C56E1CF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B2AF7BAB-E974-42A8-93A2-6CFE10BD8919} = {B7063BC9-D86B-49CE-90AD-7743788F7FC0}
{4DAA0A9D-056E-4429-8C04-83715A93B56E} = {339381AB-344C-47CD-BA9D-30310AEB8DFF}
{038E3540-8594-4DC5-965D-7F24C56E1CF2} = {21867C30-38A2-44B0-AF3C-6C49F069734F}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
init:
- git config --global core.autocrlf true
build_script:
- build.cmd --quiet verify
clone_depth: 1
test: off
deploy: off
28 changes: 28 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@echo off
cd %~dp0

SETLOCAL
SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe

IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"

:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul

:restore
IF EXIST packages\KoreBuild goto run
.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion

IF "%SKIP_DNX_INSTALL%"=="1" goto run
CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86
CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86

:run
CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
39 changes: 39 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

if test `uname` = Darwin; then
cachedir=~/Library/Caches/KBuild
else
if [ -z $XDG_DATA_HOME ]; then
cachedir=$HOME/.local/share
else
cachedir=$XDG_DATA_HOME;
fi
fi
mkdir -p $cachedir

url=https://www.nuget.org/nuget.exe

if test ! -f $cachedir/nuget.exe; then
wget -O $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null
fi

if test ! -e .nuget; then
mkdir .nuget
cp $cachedir/nuget.exe .nuget/nuget.exe
fi

if test ! -d packages/KoreBuild; then
mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion
fi

if ! type dnvm > /dev/null 2>&1; then
source packages/KoreBuild/build/dnvm.sh
fi

if ! type dnx > /dev/null 2>&1; then
dnvm upgrade
fi

mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"

3 changes: 3 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projects": [ "src", "test" ]
}
8 changes: 8 additions & 0 deletions makefile.shade
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use namespace="System.Net"

var VERSION='0.1'
var FULL_VERSION='0.1'
var AUTHORS='Microsoft Open Technologies, Inc.'

use-standard-lifecycle
k-standard-goals
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>038e3540-8594-4dc5-965d-7f24c56e1cf2</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>55709</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
24 changes: 24 additions & 0 deletions samples/Microsoft.AspNet.Proxy.Samples/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;

namespace Microsoft.AspNet.Proxy
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
const string scheme = "https";
const string host = "example.com";
const string port = "443";
var options = new ProxyOptions()
{
Scheme = scheme,
Host = host,
Port = port
};
app.RunProxy(options);
}
}
}
2 changes: 2 additions & 0 deletions samples/Microsoft.AspNet.Proxy.Samples/hosting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server=Microsoft.AspNet.Server.WebListener
server.urls=http://localhost:5000
32 changes: 32 additions & 0 deletions samples/Microsoft.AspNet.Proxy.Samples/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"webroot": "wwwroot",
"version": "1.0.0-*",

"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.Proxy": "1.0.0-*"
},

"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},

"frameworks": {
"dnx451": { },
"dnxcore50": { }
},

"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
17 changes: 17 additions & 0 deletions src/Microsoft.AspNet.Proxy/Microsoft.AspNet.Proxy.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>4daa0a9d-056e-4429-8c04-83715a93b56e</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
21 changes: 21 additions & 0 deletions src/Microsoft.AspNet.Proxy/ProxyExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Proxy;

namespace Microsoft.AspNet.Builder
{
public static class ProxyExtension
{
/// <summary>
/// Sends request to remote server as specified in options
/// </summary>
/// <param name="builder"></param>
/// <param name="options">Options for setting port, host, and scheme</param>
/// <returns></returns>
public static IApplicationBuilder RunProxy(this IApplicationBuilder builder, ProxyOptions options)
{
return builder.UseMiddleware<ProxyMiddleware>(options);
}
}
}
Loading

0 comments on commit a416b4b

Please sign in to comment.