jgauffin / Griffin.WebServer

A web server built on top of Griffin.Framework
107 stars 42 forks source link

Support for Mono/Linux #12

Closed ajlennon closed 9 years ago

ajlennon commented 10 years ago

Hi,

I've been using Griffin Webserver successfully on Win32 and have now started testing out on Mono/Linux. I had a couple of problems with files in subdirectories which I think were down to path separator differences between the platforms.

To get this going I changed,

DiskFileService.cs

string GetFullPath(Uri uri)
{
            if (!uri.AbsolutePath.StartsWith(_rootUri))
                return null;

            var relativeUri = Uri.UnescapeDataString(uri.AbsolutePath.Remove(0, _rootUri.Length));
            return Path.Combine(_basePath, relativeUri.TrimStart('/').Replace('/', '\\'));
}

to

private string GetFullPath(Uri uri)
{
            if (!uri.AbsolutePath.StartsWith(_rootUri))
                return null;

            var relativeUri = Uri.UnescapeDataString(uri.AbsolutePath.Remove(0, _rootUri.Length));

            return Path.Combine(_basePath, relativeUri.TrimStart('/').Replace('/', Path.DirectorySeparatorChar));
}

I also found I had a problem with a missing / in indexes so changed,

bool TryGenerateDirectoryPage(IHttpContext context)
{
..
            foreach (var file in _fileService.GetFiles(context.Request.Uri))
            {
                var fileUri = context.Request.Uri.AbsolutePath + file.Name;
..

to

bool TryGenerateDirectoryPage(IHttpContext context)
{
..
            foreach (var file in _fileService.GetFiles(context.Request.Uri))
            {
                var fileUri = context.Request.Uri.AbsolutePath + file.Name;
                if (!fileUri.EndsWith("/"))
                    fileUri += "/";
                fileUri += file.Name;
..

Hope this helps.

Cheers,

Alex Lennon

jgauffin commented 9 years ago

thanks :)