reducing potential keep-alive connections to 1 per hostname (not per IP)
This commit is contained in:
parent
7973cc9600
commit
d02ae808a1
@ -20,9 +20,11 @@ func GetRunner(endpoint string) RunningInstance {
|
||||
if exists == false {
|
||||
o := RunningInstance{}
|
||||
|
||||
//tr := &http.Transport{MaxIdleConns: 10, IdleConnTimeout: 7200 * time.Second}
|
||||
tr := &http.Transport{MaxIdleConns: 10, IdleConnTimeout: 7200 * time.Second}
|
||||
|
||||
o.client = http.Client{Transport: tr}
|
||||
//o.client = http.Client{}
|
||||
o.Status = KEEPALIVE
|
||||
runninginstances[endpoint] = o
|
||||
}
|
||||
|
2
oauth.go
2
oauth.go
@ -178,7 +178,7 @@ func oauth_login(endpoint string, o *RunningInstance, username string, password
|
||||
}
|
||||
|
||||
func oauth_refresh(endpoint string, client_id string, client_secret string, refresh_token string) (OAuth, error) {
|
||||
authMap, err := json.Marshal(map[string]string{
|
||||
authMap, _ := json.Marshal(map[string]string{
|
||||
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
|
||||
"grant_type": "refresh_token",
|
||||
"scope": "read write follow push",
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@ -112,6 +113,8 @@ func check_post(uri string) (PostJson, error) {
|
||||
if err != nil {
|
||||
return postjson, errors.New("Read error on " + uri)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
err = json.Unmarshal(body, &postjson)
|
||||
if err != nil {
|
||||
return postjson, err
|
||||
@ -188,6 +191,10 @@ func check_user(uri string) (UserJson, error) {
|
||||
return userjson, err
|
||||
}
|
||||
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
|
||||
resp.Body.Close()
|
||||
|
||||
_, err = pool.Exec(context.Background(), "INSERT INTO accounts (id, actor_type, inbox, outbox, followers, following, url, preferredUsername, name, summary, icon, image, publicKey, instance) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", userjson.ID, userjson.Type, userjson.Inbox, userjson.Outbox, userjson.Followers, userjson.Following, userjson.Url, userjson.PreferredUsername, userjson.Name, userjson.Summary, userjson.Icon.Url, userjson.Image.Url, userjson.PublicKey.PublicKeyPem, userjson.instance)
|
||||
if err != nil {
|
||||
// log.Print("INSERT accounts error: ", err)
|
||||
|
@ -10,10 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func StreamMastodon(endpoint string, o *RunningInstance) {
|
||||
http_client := http.Client{}
|
||||
stream_client := http.Client{}
|
||||
|
||||
//var client_id string
|
||||
//var client_secret string
|
||||
var oauthData OAuth
|
||||
var retry bool
|
||||
|
||||
@ -46,7 +44,7 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := http_client.Do(req)
|
||||
resp, err := stream_client.Do(req)
|
||||
if err != nil {
|
||||
log.Print("Unable to stream "+api_timeline+": ", err)
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user