Fresh start (#110)
* Fresh start * Create an xml include plugin (#111) * Restructure and add testing (#114) * rooibos setup * Restructure and add testing * docs * Restore manifestpipi * Description in tools * A bit of docs * Auto bind feature (#115) * Auto bind feature * Fix children merge * bs plugin fix * Feature/app controller (#120) * Initial layout * Restructuring and plugin work * A couple of tweaks in binding stuff * tweaks * basic stack * Add basic app controller * Support json5/yaml in playlet config files (#123) * Support json5 in playlet config files * Add yaml to the mix * Delete old lib project * plugin fix * plugin tweak * verbose logging * Revert "verbose logging" This reverts commit 25867f4226703d83102519a0d48d1cc46a9876de. * One idea to fix the include plugin * Fix instability in plugins * Feature/navbar (#126) * Navbar * typo * comment * Single content node, and tests * Remove unused field * tweaks * update dependencies command * tweak formatting * Add web app screen * Set id in created screens * Search screen * Tests * Show playlists and channels in search results * Move screen stuff to app controller * Home screen (wip) * Add preferences node * README.md copyedits (#130) * README.md: Fix typos * README.md: Standardize capitalization and punctuation * Update docs/README.md --------- Co-authored-by: Brahim Hadriche <brahim.hadriche@gmail.com> * Web server: round 1 (#131) * web server object * Logging * Web server round 1 * Lint fix * Small tweaks --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Logging to file * Leftover * Add logs file to web server * Fix for timeout * Disable keepalive connection * add openapi spec file * Lint fix * add prefs version in api * Add ecp api definition * Lint fix * Settings rework (#135) * Settings rework * Standard OnFocusChange event * Video player stuff (#136) * Video player stuff * Restructure things so that focus is better handled * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Exit dialog * A bunch of changes * New http client * Set TODO priorities * picture in picture * mark video watched * Video player stuff mostly there * update spec file * Sponsorblock * FuncName * SponsorBlock notifications * Lint fix * misc * remove basic auth feature flag (until we start using it) * Play queue part 1 * type fix * handle unicode in request body * SponsorBlock chapter label * modal base * remove a hack * Invidious settings * web server reduce timeout * Test for captions * Lint fix * remove rpc stuff * small change * Solve focus management * a couple of fixes * Remove a bunch of todos * feed error handling wip * Lint fix * navigation in instance settings * home screen pagination support * Refactor feed to support pagination on search page * cell loading animation * Tweak caching * delete test screen * playlist support part 1 * Basic playlist view * Restore playlist/channel handler * Refactor some content node stuff, and add an auth popup dialog * A bad implementation of a playqueue * Lint fix * playlist cast fix * Feature/web app catch up (#139) * playlist cast fix * Move things around * support playlists in web app * update api * Bump deps * Downgrade todo --------- Co-authored-by: Bryce Harrington <bryce@bryceharrington.org> Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
349 files changed
+12784
-7660
No files matched your search
@@ -0,0 +1,185 @@
|
||||
import "HttpUtils.bs"
|
||||
import "HttpSettings.bs"
|
||||
import "HttpRouter.bs"
|
||||
import "HttpConnectionState.bs"
|
||||
import "HttpConnection.bs"
|
||||
|
||||
namespace Http
|
||||
|
||||
class HttpServer
|
||||
private log as log.Logger
|
||||
|
||||
' members
|
||||
private connections = invalid
|
||||
private sockin = invalid
|
||||
private uptime = invalid
|
||||
|
||||
' initializable (copied) members
|
||||
private num_requests = 0
|
||||
private total_in = 0
|
||||
private total_out = 0
|
||||
|
||||
private routers
|
||||
|
||||
public success as boolean
|
||||
public settings as Http.HttpSettings
|
||||
public task as object
|
||||
|
||||
function new(settings as HttpSettings, task as object)
|
||||
m.log = new log.Logger("HttpServer")
|
||||
m.settings = settings
|
||||
m.task = task
|
||||
m.routers = []
|
||||
m.utils = new Utils()
|
||||
m.success = m.Init()
|
||||
end function
|
||||
|
||||
function Init() as boolean
|
||||
m.uptime = CreateObject("roTimespan")
|
||||
m.connections = CreateObject("roAssociativeArray")
|
||||
|
||||
success = true
|
||||
|
||||
' create incoming socket
|
||||
sockin = CreateObject("roStreamSocket")
|
||||
if sockin = invalid
|
||||
success = false
|
||||
m.log.error("socket()")
|
||||
end if
|
||||
|
||||
' reuse address
|
||||
if not sockin.setReuseAddr(true)
|
||||
success = false
|
||||
m.log.error("setsockopt(SO_REUSEADDR)", sockin.status())
|
||||
end if
|
||||
|
||||
' bind socket
|
||||
addrin = CreateObject("roSocketAddress")
|
||||
addrin.setPort(m.settings.Port)
|
||||
if not sockin.setAddress(addrin)
|
||||
success = false
|
||||
m.log.error("bind(port" + Stri(m.settings.Port) + ")", sockin.status())
|
||||
end if
|
||||
' listen on socket
|
||||
if not sockin.listen(m.settings.MaxConnections)
|
||||
success = false
|
||||
m.log.error("listen()", sockin.status())
|
||||
end if
|
||||
' monitor socket
|
||||
sockin.setMessagePort(m.settings.MessagePort)
|
||||
sockin.notifyReadable(true)
|
||||
|
||||
m.sockin = sockin
|
||||
|
||||
m.log.info("listening on " + addrin.getAddress())
|
||||
return success
|
||||
end function
|
||||
|
||||
function UseRouter(router as HttpRouter)
|
||||
m.routers.Push(router)
|
||||
end function
|
||||
|
||||
function PreWait()
|
||||
connections = m.connections
|
||||
for each id in connections
|
||||
conn = connections[id]
|
||||
conn.CheckTimeout(m.settings.TimeoutInMs)
|
||||
cs = conn.state
|
||||
if cs = Http.HttpConnectionState.DONE
|
||||
conn.socket.notifyReadable(false)
|
||||
conn.socket.notifyWritable(false)
|
||||
else if cs = Http.HttpConnectionState.RECV_REQUEST
|
||||
conn.socket.notifyReadable(true)
|
||||
conn.socket.notifyWritable(false)
|
||||
else if cs = Http.HttpConnectionState.SEND_HEADER or cs = Http.HttpConnectionState.SEND_RESPONSE
|
||||
conn.socket.notifyWritable(true)
|
||||
conn.socket.notifyReadable(false)
|
||||
else
|
||||
m.log.error("invalid state")
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function PostWait()
|
||||
connections = m.connections
|
||||
if m.sockin.isReadable()
|
||||
conn = m.AcceptHttpConnection()
|
||||
if conn <> invalid
|
||||
connections[conn.id] = conn
|
||||
end if
|
||||
end if
|
||||
for each id in connections
|
||||
conn = connections[id]
|
||||
cs = conn.state
|
||||
if cs = Http.HttpConnectionState.RECV_REQUEST
|
||||
if conn.socket.isReadable()
|
||||
conn.PollRequest(m)
|
||||
end if
|
||||
else if cs = Http.HttpConnectionState.SEND_HEADER
|
||||
if conn.socket.isWritable()
|
||||
conn.PollHeader(m)
|
||||
end if
|
||||
else if cs = Http.HttpConnectionState.SEND_RESPONSE
|
||||
if conn.socket.isWritable()
|
||||
conn.PollResponse(m)
|
||||
end if
|
||||
else if cs = Http.HttpConnectionState.DONE
|
||||
' handle with other connections that might transition to done
|
||||
else
|
||||
m.log.error("invalid state")
|
||||
end if
|
||||
cs = conn.state
|
||||
if cs = Http.HttpConnectionState.DONE
|
||||
if conn.close
|
||||
conn.socket.close()
|
||||
connections.delete(id)
|
||||
else if conn.ws_upgrade and m.websocket <> invalid
|
||||
m.log.info("upgrading connection to web socket")
|
||||
m.websocket.AddConnection(conn.socket)
|
||||
connections.delete(id)
|
||||
else
|
||||
conn.Recycle()
|
||||
conn.PollRequest(m)
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function AcceptHttpConnection() as HttpConnection
|
||||
sockin = m.sockin
|
||||
socket = sockin.accept()
|
||||
if not sockin.eOK()
|
||||
m.log.error("accept()", sockin.status())
|
||||
end if
|
||||
if socket = invalid
|
||||
return invalid
|
||||
end if
|
||||
conn = new HttpConnection(m, m.settings)
|
||||
conn.Accepted(m, socket)
|
||||
return conn
|
||||
end function
|
||||
|
||||
function Close()
|
||||
' close all the sockets
|
||||
m.sockin.close()
|
||||
connections = m.connections
|
||||
for each id in connections
|
||||
conn = connections[id]
|
||||
conn.socket.close()
|
||||
end for
|
||||
if m.websocket <> invalid
|
||||
m.websocket.Close()
|
||||
end if
|
||||
' final stats
|
||||
m.log.info(`\n` + m.stats())
|
||||
end function
|
||||
|
||||
function Stats() as string
|
||||
stats = " Uptime" + Stri(m.uptime.totalSeconds()) + " secs" + `\n`
|
||||
stats = stats + " Requests" + Stri(m.num_requests) + `\n`
|
||||
stats = stats + " Bytes" + Stri(m.total_in) + " in," + Stri(m.total_out) + " out"
|
||||
return stats
|
||||
end function
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user