Comments (8)
@leavengood , I mentioned your library in README.md.
from fasthttp.
I have a rough version working now. The gorilla Upgrade
method is pretty tied in with how net/http
does hijacking (which I must admit is pretty hard to use as alluded to in the README for fasthttp), and it was hard to even try to refactor it for fasthttp. So for now I ended up just adding an exported NewServerConn
function to gorilla that takes a *net.Conn
and just calls the existing newConn
to create a *websocket.Conn
. I then made my own fasthttp.Handler
which does all the necessary checks of the HTTP request for websockets, calls ctx.Hijack()
and returns the Switching Protocols status code.
This works fine with my simple JavaScript websockets code.
I still think this would be better if done in gorilla, so I will try adding that next. I made just have to add a new FastHTTPUpgrader
struct or something like that, since Upgrader
is pretty tied to net/http
. The good news is that websocket.Conn doesn't depend on net/http
at all, and it does most of the hard work for websockets.
I don't yet know if the gorilla project will be open to adding support for fasthttp
though, even if I do all the work.
from fasthttp.
If anyone is working on this, or if there are other ideas on how to get websockets working with fasthttp, please reply.
@leavengood , there are plans to add websockets support to fasthttp, but currently I'm busy with other stuff. So it would be great if somebody implements websockets on top of fasthttp.
from fasthttp.
I have implemented a first attempt at supporting fasthttp in the gorilla websocket package. It can be seen in my fork:
A lot of the changes are just making various utility functions usable for both net/http
and fasthttp
, but the "meat" of it is here:
leavengood/websocket@a24f11b#diff-34c6b408d72845d076d47126c29948d1R222
I have copied the style of the normal Upgrader
a bit, and it works, but I don't know how much it fits in with the style of fasthttp. Here is an example of what using it would look like:
handler := func(c *websocket.Conn) {
// Do something with the connection
}
upgrader := &websocket.FastHTTPUpgrader{
Handler: handler,
// Don't check the origin header
CheckOrigin: func(ctx *fasthttp.RequestCtx) bool { return true },
}
if err := fasthttp.ListenAndServe(":12345", upgrader.UpgradeHandler); err != nil {
log.Fatalf("Error in ListenAndServe: %s", err)
}
Let me know what you think of this, and I can see about adding some tests and then making a PR to the main gorilla websocket repo.
from fasthttp.
I made a PR and have made some adjustments to account for fasthttp
needing Go 1.4 or above:
from fasthttp.
@leavengood , gorilla/websocket#98 looks cool! It would be great if it will be merged eventually into gorilla websockets.
from fasthttp.
It may need some more tweaking but they seem to be open to the idea. Worse case I could maintain a fork with fasthttp support. Their project seems pretty stable with a few commits now and then, so it wouldn't be hard to keep a fork up-to-date. For the moment if other people need this they can use my fork, though at the moment the new code is in a fasthttp branch.
from fasthttp.
Gorilla websockets does not currently want to merge in my changes, so I have closed the PR and merged that code into the master branch of my fork (https://github.com/leavengood/websocket). If anyone wishes to use websockets with fasthttp, they can import my fork. I'm going to close this issue as well.
from fasthttp.
Related Issues (20)
- Propagate request error to RetryIfFunc HOT 1
- Expose `timeout` field in Request HOT 1
- NewFastHTTPHandler does not set response status code. HOT 1
- NewFastHTTPHandler does not set response status code HOT 7
- Error when serving connection "x.x.x.x:443"<->"172.56.198.126:18271": EOF HOT 3
- http parsing of the request line - where does that happen? HOT 1
- gnet is going to have tls working on it very soon. was wondering if anyone has tried to port fasthttp to use gnet instead. HOT 1
- Feature request : update and show all examples for doing zero allocation when using fasthttp. 100% zero alloc for each req / resp. HOT 3
- It is not safe to read all stream body to memory without a max size limit. HOT 4
- serving a compress enabled public folder without +w permissions results in a 404 HOT 1
- no free connections available to host HOT 3
- when setting MaxConnsPerIP to value greater than zero, the TLSConnectionState( ) is null on a TLS connection returned from the worker pool. HOT 11
- invalid memory address or nil pointer dereference for firstByteReader'c HOT 2
- peeking nested query args HOT 1
- Incorrect Tag for version 1.54.0 HOT 1
- PFlag/Cobra compatibility in prefork HOT 1
- `\r` is improperly permitted in header names. HOT 1
- How to Optimize the Performance of My fasthttp Client in a Production Environment HOT 1
- `\r` and `\x00` are improperly permitted in header values HOT 1
- fasthttp.FS won't return Content-Encoding when files are too small HOT 4
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 fasthttp.