Skip to content

Commit

Permalink
Mod statis modify (bfenetworks#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofei0800 authored and iyangsj committed Nov 20, 2019
1 parent a228bcf commit ef7e9e3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
24 changes: 24 additions & 0 deletions bfe_modules/mod_static/mod_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ func (m *ModuleStatic) loadConfData(query url.Values) error {
return nil
}

func (m *ModuleStatic) getState(params map[string][]string) ([]byte, error) {
s := m.metrics.GetAll()
return s.Format(params)
}

func (m *ModuleStatic) getStateDiff(params map[string][]string) ([]byte, error) {
s := m.metrics.GetDiff()
return s.Format(params)
}

func (m *ModuleStatic) monitorHandlers() map[string]interface{} {
handlers := map[string]interface{}{
m.name: m.getState,
m.name + ".diff": m.getStateDiff,
}
return handlers
}

func errorStatusCode(err error) int {
if os.IsNotExist(err) {
return bfe_http.StatusNotFound
Expand Down Expand Up @@ -169,6 +187,7 @@ func (m *ModuleStatic) createRespFromStaticFile(req *bfe_basic.Request,
return resp
}
if fileInfo.IsDir() {
file.Close()
file, err = m.tryDefaultFile(root, defaultFile)
if err != nil {
resp.StatusCode = errorStatusCode(err)
Expand Down Expand Up @@ -225,6 +244,11 @@ func (m *ModuleStatic) Init(cbs *bfe_module.BfeCallbacks, whs *web_monitor.WebHa
return fmt.Errorf("%s.Init(): AddFilter(m.staticFileHandler): %v", m.name, err)
}

err = web_monitor.RegisterHandlers(whs, web_monitor.WEB_HANDLE_MONITOR, m.monitorHandlers())
if err != nil {
return fmt.Errorf("%s.Init():RegisterHandlers(m.monitorHandlers): %s", m.name, err.Error())
}

err = whs.RegisterHandler(web_monitor.WEB_HANDLE_RELOAD, m.name, m.loadConfData)
if err != nil {
return fmt.Errorf("%s.Init(): RegisterHandler(m.loadConfData): %v", m.name, err)
Expand Down
3 changes: 2 additions & 1 deletion bfe_server/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,10 @@ func (p *ReverseProxy) ServeHTTP(rw bfe_http.ResponseWriter, basicReq *bfe_basic

// for read next request
defer p.setTimeout(bfe_basic.StageEndRequest, basicReq.Connection, req, cluster.TimeoutReadClientAgain())
defer res.Body.Close()

response_got:
defer res.Body.Close()

// Callback for HANDLE_READ_BACKEND
hl = srv.CallBacks.GetHandlerList(bfe_module.HANDLE_READ_BACKEND)
if hl != nil {
Expand Down
7 changes: 7 additions & 0 deletions conf/mod_static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>

<body>
<p>Welcome to BFE!</p>
</body>

</html>
4 changes: 2 additions & 2 deletions conf/mod_static/static_rule.data
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"Config": {
"example_product": [
{
"Cond": "req_host_in(\"www.example.org\")",
"Cond": "req_host_in(\"example.org\")",
"Action": {
"Cmd": "BROWSE",
"Params": [
"./",
"../conf/mod_static",
"index.html"
]
}
Expand Down

0 comments on commit ef7e9e3

Please sign in to comment.