better Send() function
This commit is contained in:
parent
0e05b773cf
commit
4a27e7702b
|
@ -81,3 +81,39 @@ func (f *Forge) submitPatchset(pset *Patchset) error {
|
||||||
log.Info("Total patches sent ok:", newpb.Len())
|
log.Info("Total patches sent ok:", newpb.Len())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Forge) SubmitPatchesNew(pset *Patches, urlpath string) (*Patches, error) {
|
||||||
|
var url string
|
||||||
|
url = f.forgeURL + "oldpatchset"
|
||||||
|
msg, err := pset.Marshal()
|
||||||
|
if err != nil {
|
||||||
|
log.Info("proto.Marshal() failed:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Info("proto.Marshal() msg len", len(msg))
|
||||||
|
body, err := f.HttpPost(url, msg)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("httpPost() failed:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
newpb := NewPatches()
|
||||||
|
if err := newpb.Unmarshal(body); err != nil {
|
||||||
|
cfcheck := string(body[0:100])
|
||||||
|
if strings.Contains(cfcheck, "<title>Just a moment...</title>") {
|
||||||
|
return nil, log.Errorf("Cloudflare throttled this attempt to submit. TODO: fix this")
|
||||||
|
} else {
|
||||||
|
log.Infof("forged DID NOT SEND BACK PROTOBUF len(body)=%d %s (TODO: look for failure on cloudflare 'is human' check here)\n", len(body), body[0:100])
|
||||||
|
// log.Infof("TODO: try to identify data here len(body)=%d body[0:40]=%s\n", len(body), body[0:40])
|
||||||
|
// log.Info("BODY START:", body[0:10], string(body[0:10]))
|
||||||
|
// log.Info(string(body))
|
||||||
|
// if err := newpb.UnmarshalTEXT(body[2:]); err == nil {
|
||||||
|
// log.Info("wow, that did work. newpb.Len() =", newpb.Len())
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Total patches sent ok:", newpb.Len())
|
||||||
|
return newpb, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue