Skip to content

Commit

Permalink
Correct http response body close
Browse files Browse the repository at this point in the history
  • Loading branch information
llemeurfr committed Dec 28, 2024
1 parent 4e6f850 commit 096f7c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions encrypt/notify_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func NotifyLCPServer(pub Publication, lcpsv string, v2 bool, username string, pa
if err != nil {
return err
}
defer resp.Body.Close()

if (resp.StatusCode != 302) && (resp.StatusCode/100) != 2 { //302=found or 20x reply = OK
return fmt.Errorf("the server returned an error %d", resp.StatusCode)
}
Expand Down Expand Up @@ -187,6 +189,8 @@ func AbortNotification(pub Publication, lcpsv string, v2 bool, username string,
if err != nil {
return err
}
defer resp.Body.Close()

if (resp.StatusCode != 302) && (resp.StatusCode/100) != 2 { //302=found or 20x reply = OK
return fmt.Errorf("the server returned an error %d", resp.StatusCode)
}
Expand Down Expand Up @@ -262,6 +266,8 @@ func NotifyCMS(pub Publication, notifyURL string, verbose bool) error {
if err != nil {
return err
}
defer resp.Body.Close()

if (resp.StatusCode != 302) && (resp.StatusCode/100) != 2 { //302=found or 20x reply = OK
return fmt.Errorf("the server returned an error %d", resp.StatusCode)
}
Expand Down
12 changes: 6 additions & 6 deletions frontend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
"github.com/readium/readium-lcp-server/frontend/webuser"
)

//Server struct contains server info and db interfaces
// Server struct contains server info and db interfaces
type Server struct {
http.Server
readonly bool
Expand Down Expand Up @@ -197,14 +197,14 @@ func fetchLicenseStatusesTask(s *Server) {
log.Println("No http connection - no fetch this time")
return
}
defer res.Body.Close()

// get all licence status documents from the lsd server
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Println("Failed to read from the http connection - no fetch this time")
return
}
defer res.Body.Close()

// clear the db
err = s.license.PurgeDataBase()
Expand All @@ -229,22 +229,22 @@ func (server *Server) PublicationAPI() webpublication.WebPublication {
return server.publications
}

//UserAPI ( staticapi.IServer )returns DB interface for users
// UserAPI ( staticapi.IServer )returns DB interface for users
func (server *Server) UserAPI() webuser.WebUser {
return server.users
}

//PurchaseAPI ( staticapi.IServer )returns DB interface for purchases
// PurchaseAPI ( staticapi.IServer )returns DB interface for purchases
func (server *Server) PurchaseAPI() webpurchase.WebPurchase {
return server.purchases
}

//DashboardAPI ( staticapi.IServer )returns DB interface for dashboard
// DashboardAPI ( staticapi.IServer )returns DB interface for dashboard
func (server *Server) DashboardAPI() webdashboard.WebDashboard {
return server.dashboard
}

//LicenseAPI ( staticapi.IServer )returns DB interface for license
// LicenseAPI ( staticapi.IServer )returns DB interface for license
func (server *Server) LicenseAPI() weblicense.WebLicense {
return server.license
}
Expand Down

0 comments on commit 096f7c4

Please sign in to comment.