30 | my $cs_code = $1;
31 | my $un_code = $2;
32 | my $un_name = $3;
33 |
34 | # Produce UTF-8 sequence from character code;
35 |
36 | my $un_utf8 = join('', map { sprintf("%02X", $_) } unpack("C*", pack("U", hex($un_code))));
37 |
38 | print " $cs_code $un_utf8 ; $un_name\n";
39 |
40 | } else {
41 | warn "Unrecognized line: '$_'";
42 | }
43 | }
44 |
45 | ###############################################################################
46 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/contrib/vim/ftdetect/nginx.vim:
--------------------------------------------------------------------------------
1 | au BufRead,BufNewFile *.nginx set ft=nginx
2 | au BufRead,BufNewFile */etc/nginx/* set ft=nginx
3 | au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx
4 | au BufRead,BufNewFile nginx.conf set ft=nginx
5 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/contrib/vim/indent/nginx.vim:
--------------------------------------------------------------------------------
1 | if exists("b:did_indent")
2 | finish
3 | endif
4 | let b:did_indent = 1
5 |
6 | setlocal indentexpr=
7 |
8 | " cindent actually works for nginx' simple file structure
9 | setlocal cindent
10 | " Just make sure that the comments are not reset as defs would be.
11 | setlocal cinkeys-=0#
12 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/docs/LICENSE:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002-2014 Igor Sysoev
3 | * Copyright (C) 2011-2014 Nginx, Inc.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 | * SUCH DAMAGE.
26 | */
27 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/docs/PCRE.LICENCE:
--------------------------------------------------------------------------------
1 | PCRE LICENCE
2 | ------------
3 |
4 | PCRE is a library of functions to support regular expressions whose syntax
5 | and semantics are as close as possible to those of the Perl 5 language.
6 |
7 | Release 8 of PCRE is distributed under the terms of the "BSD" licence, as
8 | specified below. The documentation for PCRE, supplied in the "doc"
9 | directory, is distributed under the same terms as the software itself.
10 |
11 | The basic library functions are written in C and are freestanding. Also
12 | included in the distribution is a set of C++ wrapper functions, and a
13 | just-in-time compiler that can be used to optimize pattern matching. These
14 | are both optional features that can be omitted when the library is built.
15 |
16 |
17 | THE BASIC LIBRARY FUNCTIONS
18 | ---------------------------
19 |
20 | Written by: Philip Hazel
21 | Email local part: ph10
22 | Email domain: cam.ac.uk
23 |
24 | University of Cambridge Computing Service,
25 | Cambridge, England.
26 |
27 | Copyright (c) 1997-2014 University of Cambridge
28 | All rights reserved.
29 |
30 |
31 | PCRE JUST-IN-TIME COMPILATION SUPPORT
32 | -------------------------------------
33 |
34 | Written by: Zoltan Herczeg
35 | Email local part: hzmester
36 | Emain domain: freemail.hu
37 |
38 | Copyright(c) 2010-2014 Zoltan Herczeg
39 | All rights reserved.
40 |
41 |
42 | STACK-LESS JUST-IN-TIME COMPILER
43 | --------------------------------
44 |
45 | Written by: Zoltan Herczeg
46 | Email local part: hzmester
47 | Emain domain: freemail.hu
48 |
49 | Copyright(c) 2009-2014 Zoltan Herczeg
50 | All rights reserved.
51 |
52 |
53 | THE C++ WRAPPER FUNCTIONS
54 | -------------------------
55 |
56 | Contributed by: Google Inc.
57 |
58 | Copyright (c) 2007-2012, Google Inc.
59 | All rights reserved.
60 |
61 |
62 | THE "BSD" LICENCE
63 | -----------------
64 |
65 | Redistribution and use in source and binary forms, with or without
66 | modification, are permitted provided that the following conditions are met:
67 |
68 | * Redistributions of source code must retain the above copyright notice,
69 | this list of conditions and the following disclaimer.
70 |
71 | * Redistributions in binary form must reproduce the above copyright
72 | notice, this list of conditions and the following disclaimer in the
73 | documentation and/or other materials provided with the distribution.
74 |
75 | * Neither the name of the University of Cambridge nor the name of Google
76 | Inc. nor the names of their contributors may be used to endorse or
77 | promote products derived from this software without specific prior
78 | written permission.
79 |
80 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
81 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
84 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
85 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
86 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
87 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
88 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
89 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90 | POSSIBILITY OF SUCH DAMAGE.
91 |
92 | End
93 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/docs/README:
--------------------------------------------------------------------------------
1 |
2 | Documentation is available at http://nginx.org
3 |
4 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/docs/zlib.LICENSE:
--------------------------------------------------------------------------------
1 | (C) 1995-2013 Jean-loup Gailly and Mark Adler
2 |
3 | This software is provided 'as-is', without any express or implied
4 | warranty. In no event will the authors be held liable for any damages
5 | arising from the use of this software.
6 |
7 | Permission is granted to anyone to use this software for any purpose,
8 | including commercial applications, and to alter it and redistribute it
9 | freely, subject to the following restrictions:
10 |
11 | 1. The origin of this software must not be misrepresented; you must not
12 | claim that you wrote the original software. If you use this software
13 | in a product, an acknowledgment in the product documentation would be
14 | appreciated but is not required.
15 | 2. Altered source versions must be plainly marked as such, and must not be
16 | misrepresented as being the original software.
17 | 3. This notice may not be removed or altered from any source distribution.
18 |
19 | Jean-loup Gailly Mark Adler
20 | jloup@gzip.org madler@alumni.caltech.edu
21 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/html/50x.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Error
5 |
12 |
13 |
14 | An error occurred.
15 | Sorry, the page you are looking for is currently unavailable.
16 | Please try again later.
17 | If you are the system administrator of this resource then you should check
18 | the error log for details.
19 | Faithfully yours, nginx.
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Welcome to nginx!
5 |
12 |
13 |
14 | Welcome to nginx!
15 | If you see this page, the nginx web server is successfully installed and
16 | working. Further configuration is required.
17 |
18 | For online documentation and support please refer to
19 | nginx.org.
20 | Commercial support is available at
21 | nginx.com.
22 |
23 | Thank you for using nginx.
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Examples/windows-nginx-1.6.2/nginx.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gigi81/sharpfastcgi/e5aeead9f9be13e423067de2de876ba9821f81b2/Examples/windows-nginx-1.6.2/nginx.exe
--------------------------------------------------------------------------------
/FastCgi.AspNet/AspNetChannel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Grillisoft.FastCgi.Protocol;
6 |
7 | namespace Grillisoft.FastCgi.AspNet
8 | {
9 | public class AspNetChannel : FastCgiChannel
10 | {
11 | private readonly IAspNetRequestConfig _config;
12 |
13 | public AspNetChannel(ILowerLayer lowerLayer, ILoggerFactory loggerFactory, IAspNetRequestConfig config)
14 | : base(lowerLayer, new Repositories.SyncronizedRequestsRepository(), loggerFactory)
15 | {
16 | _config = config;
17 | }
18 |
19 | protected override Request CreateRequest(ushort requestId, BeginRequestMessageBody body)
20 | {
21 | return new AspNetRequest(requestId, body, _config);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/AspNetChannelFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Grillisoft.FastCgi;
3 | using Grillisoft.FastCgi.Protocol;
4 | using Grillisoft.FastCgi.AspNet;
5 |
6 | namespace Grillisoft.FastCgi.AspNet
7 | {
8 | public class AspNetChannelFactory : IFastCgiChannelFactory
9 | {
10 | ILoggerFactory _loggerFactory;
11 | IAspNetRequestConfig _requestConfig;
12 |
13 | public AspNetChannelFactory (ILoggerFactory loggerFactory, IAspNetRequestConfig requestConfig)
14 | {
15 | _loggerFactory = loggerFactory;
16 | _requestConfig = requestConfig;
17 | }
18 |
19 | ///
20 | /// Creates a new FastCgiChannel
21 | ///
22 | /// Lower used to communicate with the web server
23 | public FastCgiChannel CreateChannel(ILowerLayer tcpLayer)
24 | {
25 | return new AspNetChannel(tcpLayer, _loggerFactory, _requestConfig);
26 | }
27 | }
28 |
29 | public class AspNetRequestConfig : IAspNetRequestConfig
30 | {
31 | public string VirtualPath { get; set; }
32 |
33 | public string PhysicalPath { get; set ; }
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/AspNetHosting.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | //*****************************************************************************/
3 | // Copyright (c) 2012 Luigi Grilli
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 | //*****************************************************************************/
23 | #endregion
24 |
25 | using System;
26 | using System.Web;
27 | using System.Web.Hosting;
28 | using System.IO;
29 | using System.Runtime.Remoting;
30 | using System.Globalization;
31 |
32 | namespace FastCgi.AspNet
33 | {
34 | public class MyAspHost
35 | {
36 | public static object CreateApplicationHost(Type hostType, string virtualDir, string physicalDir)
37 | {
38 | if (!(physicalDir.EndsWith("\\")))
39 | physicalDir = physicalDir + "\\";
40 |
41 | string aspDir = HttpRuntime.AspInstallDirectory;
42 | string domainId = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo).GetHashCode().ToString("x");
43 | string appName = (virtualDir + physicalDir).GetHashCode().ToString("x");
44 |
45 | AppDomainSetup setup = new AppDomainSetup();
46 | setup.ApplicationName = appName;
47 | setup.ConfigurationFile = "web.config"; // not necessary execept for debugging
48 | AppDomain ad = AppDomain.CreateDomain(domainId, null, setup);
49 | ad.SetData(".appDomain", "*");
50 | ad.SetData(".appPath", physicalDir);
51 | ad.SetData(".appVPath", virtualDir);
52 | ad.SetData(".domainId", domainId);
53 | ad.SetData(".hostingVirtualPath", virtualDir);
54 | ad.SetData(".hostingInstallDir", aspDir);
55 | ObjectHandle oh = ad.CreateInstance(hostType.Module.Assembly.FullName, hostType.FullName);
56 | return oh.Unwrap();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/AspNetRequest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | //*****************************************************************************/
3 | // Copyright (c) 2012 Luigi Grilli
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 | //*****************************************************************************/
23 | #endregion
24 |
25 | using System;
26 | using System.Collections.Generic;
27 | using System.Collections.Specialized;
28 | using System.Text;
29 | using System.Threading;
30 | using Grillisoft.FastCgi.Protocol;
31 | using ByteArray = Grillisoft.ImmutableArray.ImmutableArray;
32 | using System.Threading.Tasks;
33 | using System.Web.Hosting;
34 |
35 | namespace Grillisoft.FastCgi.AspNet
36 | {
37 | public class AspNetRequest : Request
38 | {
39 | private IAspNetRequestConfig _config;
40 |
41 | public AspNetRequest(ushort id, BeginRequestMessageBody body, IAspNetRequestConfig config)
42 | : base(id, body)
43 | {
44 | _config = config;
45 | this.Status = String.Empty;
46 | this.Headers = new NameValueCollection();
47 | }
48 |
49 | public string VirtualPath { get { return _config.VirtualPath; } }
50 |
51 | public string PhysicalPath { get { return _config.PhysicalPath; } }
52 |
53 | public bool HeaderSent { get; protected set; }
54 |
55 | public string Status { get; protected set; }
56 |
57 | public NameValueCollection Headers { get; protected set; }
58 |
59 | public void SetStatus(int statusCode, string statusDescription)
60 | {
61 | if (this.HeaderSent)
62 | throw new InvalidOperationException("Cannot set status on a response that has already been flushed");
63 |
64 | this.Status = String.Format("Status: {0} {1}", statusCode, statusDescription);
65 | }
66 |
67 | public void SetHeader(string name, string value)
68 | {
69 | if (this.HeaderSent)
70 | throw new InvalidOperationException("Cannot set headers on a response that has already been flushed");
71 |
72 | this.Headers.Set(name, value);
73 | }
74 |
75 | protected override void OnOutputStreamFlushing(FlushEventArgs args)
76 | {
77 | if (!this.HeaderSent)
78 | {
79 | args = new FlushEventArgs(this.SerializeHeaders() + args.Data);
80 | this.HeaderSent = true;
81 | }
82 |
83 | base.OnOutputStreamFlushing(args);
84 | }
85 |
86 | public override void Execute()
87 | {
88 | System.Web.HttpRuntime.ProcessRequest(new FastCgiWorkerRequest(this));
89 | }
90 |
91 | ///
92 | /// This is single threaded so we can't abort the request
93 | ///
94 | public override void Abort()
95 | {
96 | throw new InvalidOperationException("Abort is not available");
97 | }
98 |
99 | protected virtual ByteArray SerializeHeaders()
100 | {
101 | var builder = new StringBuilder();
102 |
103 | if (!String.IsNullOrEmpty(this.Status))
104 | {
105 | builder.Append(this.Status);
106 | builder.Append("\r\n");
107 | }
108 |
109 | foreach (string key in this.Headers.Keys)
110 | {
111 | builder.Append(key);
112 | builder.Append(": ");
113 | builder.Append(this.Headers[key]);
114 | builder.Append("\r\n");
115 | }
116 |
117 | builder.Append("\r\n");
118 |
119 | //TODO: can improve performance without creating the temporary array
120 | return new ByteArray(Encoding.UTF8.GetBytes(builder.ToString()));
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/FastCgi.AspNet.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {315E3781-3E29-459B-A0D6-EF880F60D6E0}
7 | Library
8 | Properties
9 | Grillisoft.FastCgi.AspNet
10 | Grillisoft.FastCgi.AspNet
11 | v4.0
12 | 512
13 | false
14 | FastCgi.AspNet.key
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 | true
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | {A3C516B6-046B-44C2-9387-2D01646589C9}
52 | FastCgi
53 |
54 |
55 | {AFE9FDDE-332C-41A5-8DA5-6C974F9E6956}
56 | ImmutableArray
57 |
58 |
59 |
60 |
61 |
62 |
63 |
70 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/FastCgi.AspNet.key:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gigi81/sharpfastcgi/e5aeead9f9be13e423067de2de876ba9821f81b2/FastCgi.AspNet/FastCgi.AspNet.key
--------------------------------------------------------------------------------
/FastCgi.AspNet/FastCgi.AspNet.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | Luigi Grilli
7 | Luigi Grilli
8 | https://github.com/gigi81/sharpfastcgi/blob/master/LICENSE.txt
9 | https://github.com/gigi81/sharpfastcgi
10 | false
11 | FastCgi Aspnet integration library
12 | Initial nuget release
13 | Copyright 2018 Luigi Grilli
14 | fastcgi web server
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/FastCgiAspNetServer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Net;
5 | using System.Runtime.Remoting;
6 | using System.Threading;
7 | using System.Web.Hosting;
8 | using Grillisoft.FastCgi.Protocol;
9 | using Grillisoft.FastCgi.Servers;
10 |
11 | namespace Grillisoft.FastCgi.AspNet
12 | {
13 | public class FastCgiAspNetServer : MarshalByRefObject
14 | {
15 | private IFastCgiServer _server;
16 |
17 | ///
18 | /// Create a fastcgi server
19 | ///
20 | /// Tcp/ip port where the server will be listening for fastcgi requests
21 | /// Virtual path of your ASP.NET application
22 | /// Physical path of your ASP.NET application
23 | ///
24 | public static FastCgiAspNetServer CreateApplicationHost(IPAddress address, int port, string virtualPath, string physicalPath, ILoggerFactory loggerFactory)
25 | {
26 | var ret = (FastCgiAspNetServer)ApplicationHost.CreateApplicationHost(typeof(FastCgiAspNetServer), virtualPath, physicalPath);
27 | ret.CreateServer (address, port, virtualPath, physicalPath, loggerFactory);
28 | return ret;
29 | }
30 |
31 | private void CreateServer(IPAddress address, int port, string virtualPath, string physicalPath, ILoggerFactory loggerFactory)
32 | {
33 | var channelFactory = new AspNetChannelFactory (loggerFactory, new AspNetRequestConfig {
34 | VirtualPath = virtualPath,
35 | PhysicalPath = physicalPath
36 | });
37 |
38 | _server = new TcpServer(address, port, channelFactory);
39 | }
40 |
41 | public override object InitializeLifetimeService()
42 | {
43 | return null; //never expire lease
44 | }
45 |
46 | ///
47 | /// Start listening for incoming connections
48 | ///
49 | public void Start()
50 | {
51 | _server.Start();
52 | }
53 |
54 | ///
55 | /// Stop listening for incoming connections
56 | ///
57 | public void Stop()
58 | {
59 | _server.Stop();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/IAspNetRequestConfig.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Grillisoft.FastCgi.AspNet
7 | {
8 | public interface IAspNetRequestConfig
9 | {
10 | string VirtualPath { get; }
11 |
12 | string PhysicalPath { get; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/FastCgi.AspNet/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("FastCgi.AspNet")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FastCgi.AspNet")]
13 | [assembly: AssemblyCopyright("Copyright © Luigi Grilli 2012 - 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("63cb8c6d-e5af-4aab-b74d-76068aa6af32")]
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 |
--------------------------------------------------------------------------------
/FastCgi.Loggers.Log4Net/FastCgi.Loggers.Log4Net.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {EE31060B-980B-4E24-AE84-0DF6A0F0E95D}
8 | Library
9 | Properties
10 | Grillisoft.FastCgi.Loggers.Log4Net
11 | Grillisoft.FastCgi.Loggers.Log4Net
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\log4net.2.0.8\lib\net40-full\log4net.dll
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | {a3c516b6-046b-44c2-9387-2d01646589c9}
57 | FastCgi
58 |
59 |
60 |
61 |
68 |
--------------------------------------------------------------------------------
/FastCgi.Loggers.Log4Net/FastCgi.Loggers.Log4Net.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | Luigi Grilli
7 | Luigi Grilli
8 | https://github.com/gigi81/sharpfastcgi/blob/master/LICENSE.txt
9 | https://github.com/gigi81/sharpfastcgi
10 | false
11 | FastCgi logging log4net integration library
12 | Initial nuget release
13 | Copyright 2018 Luigi Grilli
14 | fastcgi web server
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/FastCgi.Loggers.Log4Net/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Grillisoft.FastCgi.Loggers.Log4Net
8 | {
9 | internal class Logger : Grillisoft.FastCgi.ILogger
10 | {
11 | private readonly log4net.ILog _logger;
12 |
13 | public Logger(log4net.ILog logger)
14 | {
15 | _logger = logger;
16 | }
17 |
18 | public void Log(Grillisoft.FastCgi.LogLevel level, string format, params object[] args)
19 | {
20 | switch (level)
21 | {
22 | case Grillisoft.FastCgi.LogLevel.Critical:
23 | _logger.FatalFormat(format, args);
24 | break;
25 | case Grillisoft.FastCgi.LogLevel.Error:
26 | _logger.ErrorFormat(format, args);
27 | break;
28 | case Grillisoft.FastCgi.LogLevel.Warning:
29 | _logger.WarnFormat(format, args);
30 | break;
31 | case Grillisoft.FastCgi.LogLevel.Info:
32 | _logger.InfoFormat(format, args);
33 | break;
34 | case Grillisoft.FastCgi.LogLevel.Verbose:
35 | _logger.DebugFormat(format, args);
36 | break;
37 | default:
38 | break;
39 | }
40 | }
41 |
42 | public void Log(Grillisoft.FastCgi.LogLevel level, Exception ex, string format, params object[] args)
43 | {
44 | try
45 | {
46 | format = format ?? String.Empty;
47 | args = args ?? new object[0];
48 |
49 | switch (level)
50 | {
51 | case Grillisoft.FastCgi.LogLevel.Critical:
52 | _logger.Fatal(String.Format(format, args), ex);
53 | break;
54 | case Grillisoft.FastCgi.LogLevel.Error:
55 | _logger.Error(String.Format(format, args), ex);
56 | break;
57 | case Grillisoft.FastCgi.LogLevel.Warning:
58 | _logger.Warn(String.Format(format, args), ex);
59 | break;
60 | case Grillisoft.FastCgi.LogLevel.Info:
61 | _logger.Info(String.Format(format, args), ex);
62 | break;
63 | case Grillisoft.FastCgi.LogLevel.Verbose:
64 | _logger.Debug(String.Format(format, args), ex);
65 | break;
66 | default:
67 | break;
68 | }
69 | }
70 | catch(FormatException formatException)
71 | {
72 | _logger.Error("Invalid log format", formatException);
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/FastCgi.Loggers.Log4Net/Loggerfactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Grillisoft.FastCgi.Loggers.Log4Net
4 | {
5 | [Serializable]
6 | public sealed class LoggerFactory : ILoggerFactory
7 | {
8 | public ILogger Create(Type type)
9 | {
10 | return new Logger(log4net.LogManager.GetLogger(type));
11 | }
12 |
13 | public ILogger Create(string name)
14 | {
15 | return new Logger(log4net.LogManager.GetLogger(name));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/FastCgi.Loggers.Log4Net/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("FastCgi.Loggers.Log4Net")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FastCgi.Loggers.Log4Net")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
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("728b288c-ae94-4f5f-a7d4-07cddbd92715")]
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 |
38 | [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)]
--------------------------------------------------------------------------------
/FastCgi.Loggers.Log4Net/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/FastCgi.Owin/Constants.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Collections.ObjectModel;
3 |
4 | namespace Grillisoft.FastCgi.Owin
5 | {
6 | internal static class Constants
7 | {
8 | public static readonly KeyValuePair OwinVersion = new KeyValuePair("owin.Version", "1.0");
9 |
10 | // Owin Spec states host SHOULD send a reason phrase according to RFC 2616 section 6.1.1 when not supplied by the application
11 | public static readonly IReadOnlyDictionary ReasonPhrases = new ReadOnlyDictionary(new Dictionary(){
12 | { 100, "Continue" },
13 | { 101, "Switching Protocols" },
14 | { 200, "OK" },
15 | { 201, "Created" },
16 | { 202, "Accepted" },
17 | { 203, "Non-Authoritative Information" },
18 | { 204, "No Content" },
19 | { 205, "Reset Content" },
20 | { 206, "Partial Content" },
21 | { 300, "Multiple Choices" },
22 | { 301, "Moved Permanently" },
23 | { 302, "Found" },
24 | { 303, "See Other" },
25 | { 304, "Not Modified" },
26 | { 305, "Use Proxy" },
27 | { 307, "Temporary Redirect" },
28 | { 400, "Bad Request" },
29 | { 401, "Unauthorized" },
30 | { 402, "Payment Required" },
31 | { 403, "Forbidden" },
32 | { 404, "Not Found" },
33 | { 405, "Method Not Allowed" },
34 | { 406, "Not Acceptable" },
35 | { 407, "Proxy Authentication Required" },
36 | { 408, "Request Time-out" },
37 | { 409, "Conflict" },
38 | { 410, "Gone" },
39 | { 411, "Length Required" },
40 | { 412, "Precondition Failed" },
41 | { 413, "Request Entity Too Large" },
42 | { 414, "Request-URI Too Large" },
43 | { 415, "Unsupported Media Type" },
44 | { 416, "Requested range not satisfiable" },
45 | { 417, "Expectation Failed" },
46 | { 500, "Internal Server Error" },
47 | { 501, "Not Implemented" },
48 | { 502, "Bad Gateway" },
49 | { 503, "Service Unavailable" },
50 | { 504, "Gateway Time-out" },
51 | { 505, "HTTP Version not supported" }
52 | });
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/FastCgi.Owin/FastCgi.Owin.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {22F4FD2E-F0D6-4EAF-84FC-D3F048C4A3E6}
8 | Library
9 | Properties
10 | Grillisoft.FastCgi.Owin
11 | Grillisoft.FastCgi.Owin
12 | v4.5.1
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | false
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 | false
34 |
35 |
36 |
37 | ..\packages\Microsoft.Owin.4.0.0\lib\net451\Microsoft.Owin.dll
38 |
39 |
40 | ..\packages\Owin.1.0\lib\net40\Owin.dll
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | {a3c516b6-046b-44c2-9387-2d01646589c9}
60 | FastCgi
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/FastCgi.Owin/FastCgi.Owin.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | Luigi Grilli
7 | Luigi Grilli
8 | https://github.com/gigi81/sharpfastcgi/blob/master/LICENSE.txt
9 | https://github.com/gigi81/sharpfastcgi
10 | false
11 | FastCgi Owin integration library
12 | Initial nuget release
13 | Copyright 2018 Luigi Grilli and Mike Davis
14 | fastcgi owin web server
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/FastCgi.Owin/OwinChannel.cs:
--------------------------------------------------------------------------------
1 | using Grillisoft.FastCgi.Protocol;
2 |
3 | namespace Grillisoft.FastCgi.Owin
4 | {
5 | public class OwinChannel : SimpleFastCgiChannel
6 | {
7 | Microsoft.Owin.OwinMiddleware pipeline;
8 |
9 | public OwinChannel(ILowerLayer layer, ILoggerFactory loggerFactory, Microsoft.Owin.OwinMiddleware pipeline)
10 | : base(layer, loggerFactory)
11 | {
12 | this.pipeline = pipeline;
13 | }
14 |
15 | protected override Request CreateRequest(ushort requestId, BeginRequestMessageBody body)
16 | {
17 | return new OwinRequest(requestId, body, pipeline);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/FastCgi.Owin/OwinChannelFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Grillisoft.FastCgi;
3 | using Grillisoft.FastCgi.Protocol;
4 | using Microsoft.Owin;
5 | using Microsoft.Owin.Builder;
6 | using Owin;
7 |
8 | namespace Grillisoft.FastCgi.Owin
9 | {
10 | public class OwinChannelFactory : IFastCgiChannelFactory
11 | {
12 | private readonly ILoggerFactory loggerFactory;
13 | private readonly Action appInitializer;
14 |
15 | public OwinChannelFactory(ILoggerFactory loggerFactory, Action appInitializer)
16 | {
17 | this.loggerFactory = loggerFactory;
18 | this.appInitializer = appInitializer;
19 | }
20 |
21 | public FastCgiChannel CreateChannel(ILowerLayer lowerLayer)
22 | {
23 | IAppBuilder appBuilder = new AppBuilder();
24 | appBuilder.Properties.Add(Constants.OwinVersion);
25 | appInitializer(appBuilder);
26 |
27 | OwinMiddleware pipeline = appBuilder.Build();
28 | return new OwinChannel(lowerLayer, loggerFactory, pipeline);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/FastCgi.Owin/OwinRequest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 | using System.Threading;
6 | using Grillisoft.FastCgi.Protocol;
7 | using Microsoft.Owin;
8 |
9 | namespace Grillisoft.FastCgi.Owin
10 | {
11 | public class OwinRequest : Request
12 | {
13 | private readonly OwinMiddleware pipeline;
14 | private readonly OwinContext context = new OwinContext();
15 | private List, object>> onSendHeadersCallbacks = new List, object>>();
16 | private readonly MemoryStream responseBody = new MemoryStream();
17 | private readonly CancellationTokenSource cts = new CancellationTokenSource();
18 |
19 | public OwinRequest(ushort id, BeginRequestMessageBody body, OwinMiddleware pipeline) : base(id, body)
20 | {
21 | this.pipeline = pipeline;
22 | context.Set, object>>("server.OnSendingHeaders", RegisterOnSendingHeadersCallback);
23 | }
24 |
25 | public override void Abort()
26 | {
27 | cts.Cancel();
28 | }
29 |
30 | public override void Execute()
31 | {
32 | try
33 | {
34 | SetOwinContextValues();
35 |
36 | using (var task = pipeline.Invoke(context))
37 | {
38 | task.Wait();
39 | }
40 |
41 | SendHeaders();
42 | responseBody.Position = 0;
43 | responseBody.CopyTo(this.OutputStream);
44 | }
45 | // TODO: Catch exceptions and log
46 | finally
47 | {
48 | this.End();
49 | this.responseBody.Dispose();
50 | this.cts.Dispose();
51 | }
52 | }
53 |
54 | private void SetOwinContextValues()
55 | {
56 | context.Environment.Add(Constants.OwinVersion);
57 | context.Request.CallCancelled = cts.Token;
58 | context.Request.Body = this.InputStream.Length == 0 ? Stream.Null : this.InputStream;
59 | context.Response.Body = responseBody;
60 | var headers = context.Request.Headers;
61 |
62 | foreach (var nvp in this.Parameters)
63 | {
64 | string uName = nvp.Name.ToUpperInvariant();
65 | switch (uName)
66 | {
67 | case "SERVER_PROTOCOL":
68 | context.Request.Protocol = nvp.Value;
69 | continue;
70 | case "REQUEST_METHOD":
71 | context.Request.Method = nvp.Value.ToUpperInvariant();
72 | continue;
73 | case "QUERY_STRING":
74 | context.Request.QueryString = new QueryString(nvp.Value);
75 | continue;
76 | case "HTTPS":
77 | context.Request.Scheme = nvp.Value.Equals("on", StringComparison.OrdinalIgnoreCase) ? "https" : "http";
78 | continue;
79 | case "PATH_INFO":
80 | context.Request.PathBase = new PathString(string.Empty);
81 | context.Request.Path = new PathString(nvp.Value);
82 | continue;
83 | }
84 |
85 | if (uName.StartsWith("HTTP_"))
86 | {
87 | headers.Add(uName.Substring(5).Replace('_', '-'), new string[] { nvp.Value } );
88 | }
89 | }
90 |
91 | context.Response.Protocol = context.Request.Protocol;
92 | }
93 |
94 | private void SendHeaders()
95 | {
96 | foreach (var callbackTuple in onSendHeadersCallbacks)
97 | {
98 | callbackTuple.Item1(callbackTuple.Item2);
99 | }
100 |
101 | using (var writer = new StreamWriter(this.OutputStream, Encoding.ASCII, 1024, true))
102 | {
103 | writer.WriteLine($"Status: {context.Response.StatusCode} {context.Response.ReasonPhrase ?? Constants.ReasonPhrases[context.Response.StatusCode]}");
104 |
105 | foreach (var header in context.Response.Headers)
106 | {
107 | writer.WriteLine($"{header.Key}: {string.Join(", ", header.Value)}");
108 | }
109 |
110 | if (!context.Response.ContentLength.HasValue)
111 | {
112 | writer.WriteLine($"Content-Length: {responseBody.Length}");
113 | }
114 |
115 | writer.WriteLine();
116 | }
117 | }
118 |
119 | private void RegisterOnSendingHeadersCallback(Action