Comments (2)
This could be done in user code, not inside NetCoreServer library. In HttpsServer example this could be implemented like this:
class HttpCacheSession : HttpSession
{
public HttpCacheSession(NetCoreServer.HttpServer server) : base(server) {}
protected override void OnReceivedRequest(HttpRequest request)
{
if (request.Method == "GET")
{
if (request.Url == "/")
{
var response = Cache.Find("/index.html");
if (response.Item1)
SendAsync(response.Item2);
else
SendResponseAsync(Response.MakeErrorResponse(404, "Cannot find index.html"));
}
}
else
SendResponseAsync(Response.MakeErrorResponse("Unsupported HTTP method: " + request.Method));
}
}
from netcoreserver.
thx,it work fine
string key = request.Url;
key = Uri.UnescapeDataString(key);
if (string.IsNullOrEmpty(Path.GetExtension(key)))
{
if (key.EndsWith('/'))
{
var redirect = Cache.Find(key + "index.html");
if (redirect.Item1)
{
SendAsync(redirect.Item2);
return;
}
}
else if (Cache.Find(key + "/index.html").Item1)
{
var r = Response.MakeOkResponse(307);
r.SetBody(Encoding.UTF8.GetBytes("<script>window.location=window.location.href+\"/\";</script>").AsSpan());
//r.SetHeader("Location", key + "/");
SendResponseAsync(r);
return;
}
}
from netcoreserver.
Related Issues (20)
- Fix Bug: .NetFramework 4.8 ClientWebSocket Cann't Connect To .Net8 WsSession HOT 1
- Unhandled exception in WebSocket HOT 12
- Serialize and Deserialze HOT 3
- SimpleW : a RestAPI above NetCoreServer [not an issue but a library using NetCoreServer] HOT 1
- SslClient does not work in release mode
- Feature-Request: use BufferManager and SocketAsyncEventArgsPool to optimize memory
- netcoreserver is missing NuGet package README file
- WSS on Blazor WASM .NET 8
- 发送消息过快导致部分消息偶尔无法接受到 HOT 2
- Buffer-size in the 'OnReceived' methods can get too long HOT 3
- latency in reception of the first UDP frames (lazy?)
- Buffer.Reserve Wrong Condition? HOT 1
- TCP OnReceived(buffer, 0, received); HOT 1
- Cannot connect to WssChatServer for example
- TcpServer / TcpClient OptionKeepAlive have no effect HOT 2
- Cannot access a disposed object HOT 3
- Is there anyway to get WsOpcode in OnWsReceived?
- TcpSession.SendAsync() returns true even if a message fails to send. BytesSent also increases when send fails.
- lot of stupid internal definition
- Very good idea! Good luck!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from netcoreserver.