Comments (5)
What's the use case? :)
On Friday, 20 May 2016, wt [email protected] wrote:
@dom96 https://github.com/dom96
How about adding a sugar to write streaming response with "Transfer-Encoding":
"chunked" ?import strutils, math
proc sendChunk_(response: jester.Response, data: string): Future[void] =
let dataLen = len(data)
let sizeLen = Positive(floor(log2(toFloat(dataLen)) / 4 + 1))
response.send(toHex(BiggestInt(dataLen), sizeLen) & "\r\n" & data & "\r\n")
proc endChunk_(response: jester.Response): Future[void] =
response.send("0\r\n\r\n")Test example:
routes:
get "/":
var headers = newStringTable({
"Content-Type": "text/plain",
"Transfer-Encoding": "chunked"
})
await response.sendHeaders(Http202, headers)
await sleepAsync(1000)await response.sendChunk("hello") await sleepAsync(1000) await response.sendChunk(" world") await sleepAsync(1000) await response.sendChunk("AAAAAAAAAAAAAAAAAAAAA") await sleepAsync(1000) await response.endChunk()
—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#68
from jester.
I am doing a hadoop service based on cloud. When user request a map reduce from my service, I will exec a hadoop mapreduce. The mapreduce will be long time, I want to tell user the real-time percentage progress:
[==== 30% ]
Then I should send a streaming response to user to update the percentage progress. The code looks like this:
proc mapreduceCb(response: Response): proc(data: JsonNode): Future[bool] =
proc cb(data: JsonNode): Future[bool] =
var percent = data["current"] / data["total"]
var body = %* { "state": 0, "data": percent }
response.sendChunk($body)
result = cb
routes:
post "/hadoop/mapreduce":
let headers = newStringTable({
"Content-Type": "application/json",
"Transfer-Encoding": "chunked"
})
await response.sendHeaders(Http202, headers)
var cluster = newHadoopCluster(...)
var execs = await cluster.exec(..., mapreduceCb(response)) # mapreduce
await response.endChunk()
from jester.
Just see ajax and web server, we can report real-time messages from the backend.
from jester.
I think I would prefer for this to be provided via an external library. You can easily create a jester_streaming
package or similar.
from jester.
Sure, that's also a good way.
This issure can be closed.
from jester.
Related Issues (20)
- static files respond to non-GET http methods HOT 1
- No way to get raw query parameters
- Relative staticDir behavior changed
- Double log output on http requests HOT 1
- Jester crashes when async sleeping HOT 5
- development on windows (httpbeast) HOT 1
- finally block getting called twice? HOT 3
- Support binding on IPv6 address
- `std/cgi` will be moved to nimble packages
- Runtime SIGBUS: HOT 1
- how to use the setCookie fuction? HOT 1
- Docs: adding sections
- formData identical keys
- Bump tag to give new version through nimble HOT 2
- Revert PR #171 which auto decodes URL parameters HOT 6
- The jester.nimble file needs to be updated for v0.6.0 HOT 2
- Cannot serve dynamic web pages HOT 1
- Jester is not working with nim version 2.0.0 HOT 4
- static folder not working HOT 3
- Fix for SIGSEGV: Illegal storage access from lib/system/orc.nim nimIncRefCyclic HOT 1
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 jester.