kripth / lighttp Goto Github PK
View Code? Open in Web Editor NEWLightweight asynchronous HTTP/WS client/server
License: MIT License
Lightweight asynchronous HTTP/WS client/server
License: MIT License
Currently Lighttp does not work with binary messages, only text messages. It assumes outgoing msgs are text, and ignores incoming binary msgs.
According to the WebSocket spec, found here, page 28:
To change your code to work only with binary simply change:
WebSocketConnection.send
, line 341, from 0b10000001
to 0b10000010
WebSocketConnection.onRead
, line 314, from == 1
to == 2
Obviously that is not a good fix.
Vibe.d has a receiveBinary
and a receiveText
, and overloads send
with const(char)[]
and const(ubyte[])
respectively.
Given that Lighttp uses a callback style, I recommend adding overloads to WebSocketConnection.send
and WebSocketConnection.onReceive
. It will be a breaking change, given that the current binary-signatured functions will actually send binary, not text.
I can make a Pull Request. Any reason why WebSocketConnection.send
takes a void[]
and not a ubyte[]
?
Currently, if an exception is thrown in a user-provided handler, it will get silenced. The only trace of the exception will be the "500 Server Error" page and the error message nor stack trace are not recoverable.
The suggestion is to make them possible to log, and add a new option eg. printExceptions
, preferably on by default. For example, handleRouteCatch
could be expanded to include a stderr.writeln
call:
private void handleRouteCatch(ref HandleResult result, AsyncTCPConnection client, ServerRequest req, ServerResponse res) {
try this.server.router.handle(this.server.options, result, client, req, res);
catch(Exception ex) {
import std.stdio;
res.status = StatusCodes.internalServerError;
stderr.writeln(ex);
}
}
Can self-assign.
Running examples / static, and then accessing it through browser or curl, you will find that the number of file handles opened by the system keeps increasing until an exception occurs beyond the operating system's limit on the number of files for a single process.
After checking, it was found that if isForce used the default parameter false when calling AsyncTCPConnection.kill(bool isForce = false) of libasync, it would not close the socket handle in time and truly, resulting in a straight increase in the number of connections.
util.d line: 559
function: decodeHTTP()
??:? _d_arrayboundsp [0x6e432d]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/util.d:559 bool lighttp.util.decodeHTTP(immutable(char)[], ref immutable(char)[], ref lighttp.util.Http.Headers, ref immutable(char)[]) [0x676b27]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/util.d:482 bool lighttp.util.HttpImpl!(1, 0).HttpImpl.parse(immutable(char)[]) [0x6727f5]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/server/server.d:246 void lighttp.server.server.DefaultConnection.handleImpl(immutable(char)[]) [0x6708dd]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/server/server.d:226 void lighttp.server.server.DefaultConnection.handle() [0x6707a6]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/server/server.d:213 void lighttp.server.server.DefaultConnection.onRead() [0x670604]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/server/server.d:180 void lighttp.server.server.Connection.handle(libasync.tcp.TCPEvent) [0x67051e]
/root/.dub/packages/libasync-0.8.4/libasync/source/libasync/tcp.d:302 void libasync.tcp.TCPEventHandler.opCall(libasync.tcp.TCPEvent) [0x694a89]
/root/.dub/packages/libasync-0.8.4/libasync/source/libasync/posix.d:2622 nothrow bool libasync.posix.EventLoopImpl.onTCPTraffic(int, libasync.tcp.TCPEventHandler, int, libasync.tcp.AsyncTCPConnection) [0x68870d]
/root/.dub/packages/libasync-0.8.4/libasync/source/libasync/posix.d:549 nothrow bool libasync.posix.EventLoopImpl.loop(core.time.Duration).handleEvents() [0x682aa6]
/root/.dub/packages/libasync-0.8.4/libasync/source/libasync/posix.d:602 nothrow bool libasync.posix.EventLoopImpl.loop(core.time.Duration) [0x681c60]
/root/.dub/packages/libasync-0.8.4/libasync/source/libasync/events.d:302 nothrow bool libasync.events.EventLoop.loop(core.time.Duration) [0x679951]
/root/.dub/packages/lighttp-0.5.2/lighttp/src/lighttp/server/server.d:123 void lighttp.server.server.ServerBase.run() [0x67041c]
src/app.d:39 _Dmain [0x5ee360]
Description:
Running examples/static and trying to request with curl or browser, you will find that there is a certain probability of 400 Bad request errors. I did not track the cause of the problem carefully, but simply judged the probable point of the problem.
https://github.com/Kripth/lighttp/blob/master/src/lighttp/util.d#L480
In line 480 of util.d,
we insert a line of code for observation and find that there is a high probability that an empty data parameter will be received for parse()
. This data parameter should be one of the socket processing parameters.
MacOS 10.14.6, centos7 x64, dmd 2.088.0
Is able to use SSL certificates? If yes how?
When the length of buffer reaches a certain length, AsyncTCPConnection.send (ubyte[]) has a certain probability of incomplete transmission:
server.d, line: 236
this.conn.send(cast(ubyte[])response.toString());
Hello,
I noticed that the compiler spends a lot of time when it prints out:
Using Linux EPOLL for events
Is there a way to reduce this time?
What does this do?
@Get("download") getDownload(ServerRequest req, ServerResponse res) {
res.headers["Content-Type"] = "application/json";
res.headers["Content-Disposition"] = "attachment; filename=\"test.json\";";
res.body = "{}";
}
Writing Livereload in D,
When i Do
class Client : WebSocket {
....
void sendModify(string path){
try{
this.send( JSONValue([
"command":JSONValue("reload"),
"path":JSONValue(path),
"liveCSS":JSONValue(true)
]).toString()
);
}
catch(Exception e){
writeln("Erreur",e );
}
}
If page was closed, program quit (return error code 11) without throw exception
Any help ?
Big thanks
Example url: ?param1=test¶m2=test2
How to get value param1 and param2?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.