Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into update-buford-v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicdaiya committed Jun 20, 2016
2 parents cea314e + fdca914 commit e806311
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
35 changes: 26 additions & 9 deletions gaurun/apns_http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,40 @@ import (
"github.com/RobotsAndPencils/buford/payload"
"github.com/RobotsAndPencils/buford/payload/badge"
"github.com/RobotsAndPencils/buford/push"

"golang.org/x/net/http2"
)

func NewTransportHttp2(cert tls.Certificate) (*http.Transport, error) {
config := &tls.Config{
Certificates: []tls.Certificate{cert},
}
config.BuildNameToCertificate()

transport := &http.Transport{
TLSClientConfig: config,
MaxIdleConnsPerHost: ConfGaurun.Core.WorkerNum,
}

if err := http2.ConfigureTransport(transport); err != nil {
return nil, err
}

return transport, nil
}

func NewApnsClientHttp2(certPath, keyPath string) (*http.Client, error) {
var client *http.Client
var cert tls.Certificate
var err error
cert, err = tls.LoadX509KeyPair(certPath, keyPath)
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
return client, err
return nil, err
}

client, err = push.NewClient(cert)
transport, err := NewTransportHttp2(cert)
if err != nil {
return client, err
return nil, err
}

return client, nil
return &http.Client{Transport: transport}, nil
}

func NewApnsServiceHttp2(client *http.Client) *push.Service {
Expand Down Expand Up @@ -61,7 +78,7 @@ func NewApnsPayloadHttp2(req *RequestGaurunNotification) map[string]interface{}

func NewApnsHeadersHttp2(req *RequestGaurunNotification) *push.Headers {
return &push.Headers{
Expiration: time.Unix(int64(req.Expiry), 0),
Expiration: time.Now().Add(time.Duration(int64(req.Expiry)) * time.Second).UTC(),
Topic: ConfGaurun.Ios.Topic,
}
}
Expand Down
6 changes: 6 additions & 0 deletions gaurun/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ func PushNotificationHandler(w http.ResponseWriter, r *http.Request) {
return
}

LogError.Debug("content-length check")
if r.ContentLength == 0 {
sendResponse(w, "request body is empty", http.StatusBadRequest)
return
}

var (
reqGaurun RequestGaurun
err error
Expand Down

0 comments on commit e806311

Please sign in to comment.