webhook.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "crypto/hmac"
  7. "crypto/sha256"
  8. "crypto/tls"
  9. "encoding/hex"
  10. "encoding/json"
  11. "fmt"
  12. "io/ioutil"
  13. "strings"
  14. "time"
  15. "github.com/go-xorm/xorm"
  16. gouuid "github.com/satori/go.uuid"
  17. log "gopkg.in/clog.v1"
  18. api "github.com/gogits/go-gogs-client"
  19. "github.com/gogits/gogs/modules/httplib"
  20. "github.com/gogits/gogs/modules/setting"
  21. "github.com/gogits/gogs/modules/sync"
  22. )
  23. var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength)
  24. type HookContentType int
  25. const (
  26. JSON HookContentType = iota + 1
  27. FORM
  28. )
  29. var hookContentTypes = map[string]HookContentType{
  30. "json": JSON,
  31. "form": FORM,
  32. }
  33. // ToHookContentType returns HookContentType by given name.
  34. func ToHookContentType(name string) HookContentType {
  35. return hookContentTypes[name]
  36. }
  37. func (t HookContentType) Name() string {
  38. switch t {
  39. case JSON:
  40. return "json"
  41. case FORM:
  42. return "form"
  43. }
  44. return ""
  45. }
  46. // IsValidHookContentType returns true if given name is a valid hook content type.
  47. func IsValidHookContentType(name string) bool {
  48. _, ok := hookContentTypes[name]
  49. return ok
  50. }
  51. type HookEvents struct {
  52. Create bool `json:"create"`
  53. Push bool `json:"push"`
  54. PullRequest bool `json:"pull_request"`
  55. }
  56. // HookEvent represents events that will delivery hook.
  57. type HookEvent struct {
  58. PushOnly bool `json:"push_only"`
  59. SendEverything bool `json:"send_everything"`
  60. ChooseEvents bool `json:"choose_events"`
  61. HookEvents `json:"events"`
  62. }
  63. type HookStatus int
  64. const (
  65. HOOK_STATUS_NONE = iota
  66. HOOK_STATUS_SUCCEED
  67. HOOK_STATUS_FAILED
  68. )
  69. // Webhook represents a web hook object.
  70. type Webhook struct {
  71. ID int64 `xorm:"pk autoincr"`
  72. RepoID int64
  73. OrgID int64
  74. URL string `xorm:"url TEXT"`
  75. ContentType HookContentType
  76. Secret string `xorm:"TEXT"`
  77. Events string `xorm:"TEXT"`
  78. *HookEvent `xorm:"-"`
  79. IsSSL bool `xorm:"is_ssl"`
  80. IsActive bool
  81. HookTaskType HookTaskType
  82. Meta string `xorm:"TEXT"` // store hook-specific attributes
  83. LastStatus HookStatus // Last delivery status
  84. Created time.Time `xorm:"-"`
  85. CreatedUnix int64
  86. Updated time.Time `xorm:"-"`
  87. UpdatedUnix int64
  88. }
  89. func (w *Webhook) BeforeInsert() {
  90. w.CreatedUnix = time.Now().Unix()
  91. w.UpdatedUnix = w.CreatedUnix
  92. }
  93. func (w *Webhook) BeforeUpdate() {
  94. w.UpdatedUnix = time.Now().Unix()
  95. }
  96. func (w *Webhook) AfterSet(colName string, _ xorm.Cell) {
  97. var err error
  98. switch colName {
  99. case "events":
  100. w.HookEvent = &HookEvent{}
  101. if err = json.Unmarshal([]byte(w.Events), w.HookEvent); err != nil {
  102. log.Error(3, "Unmarshal [%d]: %v", w.ID, err)
  103. }
  104. case "created_unix":
  105. w.Created = time.Unix(w.CreatedUnix, 0).Local()
  106. case "updated_unix":
  107. w.Updated = time.Unix(w.UpdatedUnix, 0).Local()
  108. }
  109. }
  110. func (w *Webhook) GetSlackHook() *SlackMeta {
  111. s := &SlackMeta{}
  112. if err := json.Unmarshal([]byte(w.Meta), s); err != nil {
  113. log.Error(2, "GetSlackHook [%d]: %v", w.ID, err)
  114. }
  115. return s
  116. }
  117. // History returns history of webhook by given conditions.
  118. func (w *Webhook) History(page int) ([]*HookTask, error) {
  119. return HookTasks(w.ID, page)
  120. }
  121. // UpdateEvent handles conversion from HookEvent to Events.
  122. func (w *Webhook) UpdateEvent() error {
  123. data, err := json.Marshal(w.HookEvent)
  124. w.Events = string(data)
  125. return err
  126. }
  127. // HasCreateEvent returns true if hook enabled create event.
  128. func (w *Webhook) HasCreateEvent() bool {
  129. return w.SendEverything ||
  130. (w.ChooseEvents && w.HookEvents.Create)
  131. }
  132. // HasPushEvent returns true if hook enabled push event.
  133. func (w *Webhook) HasPushEvent() bool {
  134. return w.PushOnly || w.SendEverything ||
  135. (w.ChooseEvents && w.HookEvents.Push)
  136. }
  137. // HasPullRequestEvent returns true if hook enabled pull request event.
  138. func (w *Webhook) HasPullRequestEvent() bool {
  139. return w.SendEverything ||
  140. (w.ChooseEvents && w.HookEvents.PullRequest)
  141. }
  142. func (w *Webhook) EventsArray() []string {
  143. events := make([]string, 0, 3)
  144. if w.HasCreateEvent() {
  145. events = append(events, "create")
  146. }
  147. if w.HasPushEvent() {
  148. events = append(events, "push")
  149. }
  150. if w.HasPullRequestEvent() {
  151. events = append(events, "pull_request")
  152. }
  153. return events
  154. }
  155. // CreateWebhook creates a new web hook.
  156. func CreateWebhook(w *Webhook) error {
  157. _, err := x.Insert(w)
  158. return err
  159. }
  160. // getWebhook uses argument bean as query condition,
  161. // ID must be specified and do not assign unnecessary fields.
  162. func getWebhook(bean *Webhook) (*Webhook, error) {
  163. has, err := x.Get(bean)
  164. if err != nil {
  165. return nil, err
  166. } else if !has {
  167. return nil, ErrWebhookNotExist{bean.ID}
  168. }
  169. return bean, nil
  170. }
  171. // GetWebhookByID returns webhook by given ID.
  172. // Use this function with caution of accessing unauthorized webhook,
  173. // which means should only be used in non-user interactive functions.
  174. func GetWebhookByID(id int64) (*Webhook, error) {
  175. return getWebhook(&Webhook{
  176. ID: id,
  177. })
  178. }
  179. // GetWebhookOfRepoByID returns webhook of repository by given ID.
  180. func GetWebhookOfRepoByID(repoID, id int64) (*Webhook, error) {
  181. return getWebhook(&Webhook{
  182. ID: id,
  183. RepoID: repoID,
  184. })
  185. }
  186. // GetWebhookByOrgID returns webhook of organization by given ID.
  187. func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) {
  188. return getWebhook(&Webhook{
  189. ID: id,
  190. OrgID: orgID,
  191. })
  192. }
  193. // GetActiveWebhooksByRepoID returns all active webhooks of repository.
  194. func GetActiveWebhooksByRepoID(repoID int64) ([]*Webhook, error) {
  195. webhooks := make([]*Webhook, 0, 5)
  196. return webhooks, x.Where("repo_id = ?", repoID).And("is_active = ?", true).Find(&webhooks)
  197. }
  198. // GetWebhooksByRepoID returns all webhooks of a repository.
  199. func GetWebhooksByRepoID(repoID int64) ([]*Webhook, error) {
  200. webhooks := make([]*Webhook, 0, 5)
  201. return webhooks, x.Find(&webhooks, &Webhook{RepoID: repoID})
  202. }
  203. // UpdateWebhook updates information of webhook.
  204. func UpdateWebhook(w *Webhook) error {
  205. _, err := x.Id(w.ID).AllCols().Update(w)
  206. return err
  207. }
  208. // deleteWebhook uses argument bean as query condition,
  209. // ID must be specified and do not assign unnecessary fields.
  210. func deleteWebhook(bean *Webhook) (err error) {
  211. sess := x.NewSession()
  212. defer sessionRelease(sess)
  213. if err = sess.Begin(); err != nil {
  214. return err
  215. }
  216. if _, err = sess.Delete(bean); err != nil {
  217. return err
  218. } else if _, err = sess.Delete(&HookTask{HookID: bean.ID}); err != nil {
  219. return err
  220. }
  221. return sess.Commit()
  222. }
  223. // DeleteWebhookOfRepoByID deletes webhook of repository by given ID.
  224. func DeleteWebhookOfRepoByID(repoID, id int64) error {
  225. return deleteWebhook(&Webhook{
  226. ID: id,
  227. RepoID: repoID,
  228. })
  229. }
  230. // DeleteWebhookOfOrgByID deletes webhook of organization by given ID.
  231. func DeleteWebhookOfOrgByID(orgID, id int64) error {
  232. return deleteWebhook(&Webhook{
  233. ID: id,
  234. OrgID: orgID,
  235. })
  236. }
  237. // GetWebhooksByOrgID returns all webhooks for an organization.
  238. func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) {
  239. err = x.Find(&ws, &Webhook{OrgID: orgID})
  240. return ws, err
  241. }
  242. // GetActiveWebhooksByOrgID returns all active webhooks for an organization.
  243. func GetActiveWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) {
  244. err = x.Where("org_id=?", orgID).And("is_active=?", true).Find(&ws)
  245. return ws, err
  246. }
  247. // ___ ___ __ ___________ __
  248. // / | \ ____ ____ | | _\__ ___/____ _____| | __
  249. // / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ /
  250. // \ Y ( <_> | <_> ) < | | / __ \_\___ \| <
  251. // \___|_ / \____/ \____/|__|_ \ |____| (____ /____ >__|_ \
  252. // \/ \/ \/ \/ \/
  253. type HookTaskType int
  254. const (
  255. GOGS HookTaskType = iota + 1
  256. SLACK
  257. DISCORD
  258. )
  259. var hookTaskTypes = map[string]HookTaskType{
  260. "gogs": GOGS,
  261. "slack": SLACK,
  262. "discord": DISCORD,
  263. }
  264. // ToHookTaskType returns HookTaskType by given name.
  265. func ToHookTaskType(name string) HookTaskType {
  266. return hookTaskTypes[name]
  267. }
  268. func (t HookTaskType) Name() string {
  269. switch t {
  270. case GOGS:
  271. return "gogs"
  272. case SLACK:
  273. return "slack"
  274. case DISCORD:
  275. return "discord"
  276. }
  277. return ""
  278. }
  279. // IsValidHookTaskType returns true if given name is a valid hook task type.
  280. func IsValidHookTaskType(name string) bool {
  281. _, ok := hookTaskTypes[name]
  282. return ok
  283. }
  284. type HookEventType string
  285. const (
  286. HOOK_EVENT_CREATE HookEventType = "create"
  287. HOOK_EVENT_PUSH HookEventType = "push"
  288. HOOK_EVENT_PULL_REQUEST HookEventType = "pull_request"
  289. )
  290. // HookRequest represents hook task request information.
  291. type HookRequest struct {
  292. Headers map[string]string `json:"headers"`
  293. }
  294. // HookResponse represents hook task response information.
  295. type HookResponse struct {
  296. Status int `json:"status"`
  297. Headers map[string]string `json:"headers"`
  298. Body string `json:"body"`
  299. }
  300. // HookTask represents a hook task.
  301. type HookTask struct {
  302. ID int64 `xorm:"pk autoincr"`
  303. RepoID int64 `xorm:"INDEX"`
  304. HookID int64
  305. UUID string
  306. Type HookTaskType
  307. URL string `xorm:"TEXT"`
  308. Signature string `xorm:"TEXT"`
  309. api.Payloader `xorm:"-"`
  310. PayloadContent string `xorm:"TEXT"`
  311. ContentType HookContentType
  312. EventType HookEventType
  313. IsSSL bool
  314. IsDelivered bool
  315. Delivered int64
  316. DeliveredString string `xorm:"-"`
  317. // History info.
  318. IsSucceed bool
  319. RequestContent string `xorm:"TEXT"`
  320. RequestInfo *HookRequest `xorm:"-"`
  321. ResponseContent string `xorm:"TEXT"`
  322. ResponseInfo *HookResponse `xorm:"-"`
  323. }
  324. func (t *HookTask) BeforeUpdate() {
  325. if t.RequestInfo != nil {
  326. t.RequestContent = t.MarshalJSON(t.RequestInfo)
  327. }
  328. if t.ResponseInfo != nil {
  329. t.ResponseContent = t.MarshalJSON(t.ResponseInfo)
  330. }
  331. }
  332. func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
  333. var err error
  334. switch colName {
  335. case "delivered":
  336. t.DeliveredString = time.Unix(0, t.Delivered).Format("2006-01-02 15:04:05 MST")
  337. case "request_content":
  338. if len(t.RequestContent) == 0 {
  339. return
  340. }
  341. t.RequestInfo = &HookRequest{}
  342. if err = json.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil {
  343. log.Error(3, "Unmarshal[%d]: %v", t.ID, err)
  344. }
  345. case "response_content":
  346. if len(t.ResponseContent) == 0 {
  347. return
  348. }
  349. t.ResponseInfo = &HookResponse{}
  350. if err = json.Unmarshal([]byte(t.ResponseContent), t.ResponseInfo); err != nil {
  351. log.Error(3, "Unmarshal [%d]: %v", t.ID, err)
  352. }
  353. }
  354. }
  355. func (t *HookTask) MarshalJSON(v interface{}) string {
  356. p, err := json.Marshal(v)
  357. if err != nil {
  358. log.Error(3, "Marshal [%d]: %v", t.ID, err)
  359. }
  360. return string(p)
  361. }
  362. // HookTasks returns a list of hook tasks by given conditions.
  363. func HookTasks(hookID int64, page int) ([]*HookTask, error) {
  364. tasks := make([]*HookTask, 0, setting.Webhook.PagingNum)
  365. return tasks, x.Limit(setting.Webhook.PagingNum, (page-1)*setting.Webhook.PagingNum).Where("hook_id=?", hookID).Desc("id").Find(&tasks)
  366. }
  367. // CreateHookTask creates a new hook task,
  368. // it handles conversion from Payload to PayloadContent.
  369. func CreateHookTask(t *HookTask) error {
  370. data, err := t.Payloader.JSONPayload()
  371. if err != nil {
  372. return err
  373. }
  374. t.UUID = gouuid.NewV4().String()
  375. t.PayloadContent = string(data)
  376. _, err = x.Insert(t)
  377. return err
  378. }
  379. // UpdateHookTask updates information of hook task.
  380. func UpdateHookTask(t *HookTask) error {
  381. _, err := x.Id(t.ID).AllCols().Update(t)
  382. return err
  383. }
  384. // prepareWebhooks adds list of webhooks to task queue.
  385. func prepareWebhooks(repo *Repository, event HookEventType, p api.Payloader, webhooks []*Webhook) (err error) {
  386. if len(webhooks) == 0 {
  387. return nil
  388. }
  389. var payloader api.Payloader
  390. for _, w := range webhooks {
  391. switch event {
  392. case HOOK_EVENT_CREATE:
  393. if !w.HasCreateEvent() {
  394. continue
  395. }
  396. case HOOK_EVENT_PUSH:
  397. if !w.HasPushEvent() {
  398. continue
  399. }
  400. case HOOK_EVENT_PULL_REQUEST:
  401. if !w.HasPullRequestEvent() {
  402. continue
  403. }
  404. }
  405. // Use separate objects so modifcations won't be made on payload on non-Gogs type hooks.
  406. switch w.HookTaskType {
  407. case SLACK:
  408. payloader, err = GetSlackPayload(p, event, w.Meta)
  409. if err != nil {
  410. return fmt.Errorf("GetSlackPayload: %v", err)
  411. }
  412. case DISCORD:
  413. payloader, err = GetDiscordPayload(p, event, w.Meta)
  414. if err != nil {
  415. return fmt.Errorf("GetDiscordPayload: %v", err)
  416. }
  417. default:
  418. payloader = p
  419. }
  420. var signature string
  421. if len(w.Secret) > 0 {
  422. data, err := payloader.JSONPayload()
  423. if err != nil {
  424. log.Error(2, "prepareWebhooks.JSONPayload: %v", err)
  425. }
  426. sig := hmac.New(sha256.New, []byte(w.Secret))
  427. sig.Write(data)
  428. signature = hex.EncodeToString(sig.Sum(nil))
  429. }
  430. if err = CreateHookTask(&HookTask{
  431. RepoID: repo.ID,
  432. HookID: w.ID,
  433. Type: w.HookTaskType,
  434. URL: w.URL,
  435. Signature: signature,
  436. Payloader: payloader,
  437. ContentType: w.ContentType,
  438. EventType: event,
  439. IsSSL: w.IsSSL,
  440. }); err != nil {
  441. return fmt.Errorf("CreateHookTask: %v", err)
  442. }
  443. }
  444. return nil
  445. }
  446. // PrepareWebhooks adds all active webhooks to task queue.
  447. func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) error {
  448. webhooks, err := GetActiveWebhooksByRepoID(repo.ID)
  449. if err != nil {
  450. return fmt.Errorf("GetActiveWebhooksByRepoID [%d]: %v", repo.ID, err)
  451. }
  452. // check if repo belongs to org and append additional webhooks
  453. if repo.MustOwner().IsOrganization() {
  454. // get hooks for org
  455. orgws, err := GetActiveWebhooksByOrgID(repo.OwnerID)
  456. if err != nil {
  457. return fmt.Errorf("GetActiveWebhooksByOrgID [%d]: %v", repo.OwnerID, err)
  458. }
  459. webhooks = append(webhooks, orgws...)
  460. }
  461. return prepareWebhooks(repo, event, p, webhooks)
  462. }
  463. // TestWebhook adds the test webhook matches the ID to task queue.
  464. func TestWebhook(repo *Repository, event HookEventType, p api.Payloader, webhookID int64) error {
  465. webhook, err := GetWebhookOfRepoByID(repo.ID, webhookID)
  466. if err != nil {
  467. return fmt.Errorf("GetWebhookOfRepoByID [repo_id: %d, id: %d]: %v", repo.ID, webhookID, err)
  468. }
  469. return prepareWebhooks(repo, event, p, []*Webhook{webhook})
  470. }
  471. func (t *HookTask) deliver() {
  472. t.IsDelivered = true
  473. timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second
  474. req := httplib.Post(t.URL).SetTimeout(timeout, timeout).
  475. Header("X-Gogs-Delivery", t.UUID).
  476. Header("X-Gogs-Signature", t.Signature).
  477. Header("X-Gogs-Event", string(t.EventType)).
  478. SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify})
  479. switch t.ContentType {
  480. case JSON:
  481. req = req.Header("Content-Type", "application/json").Body(t.PayloadContent)
  482. case FORM:
  483. req.Param("payload", t.PayloadContent)
  484. }
  485. // Record delivery information.
  486. t.RequestInfo = &HookRequest{
  487. Headers: map[string]string{},
  488. }
  489. for k, vals := range req.Headers() {
  490. t.RequestInfo.Headers[k] = strings.Join(vals, ",")
  491. }
  492. t.ResponseInfo = &HookResponse{
  493. Headers: map[string]string{},
  494. }
  495. defer func() {
  496. t.Delivered = time.Now().UnixNano()
  497. if t.IsSucceed {
  498. log.Trace("Hook delivered: %s", t.UUID)
  499. } else {
  500. log.Trace("Hook delivery failed: %s", t.UUID)
  501. }
  502. // Update webhook last delivery status.
  503. w, err := GetWebhookByID(t.HookID)
  504. if err != nil {
  505. log.Error(3, "GetWebhookByID: %v", err)
  506. return
  507. }
  508. if t.IsSucceed {
  509. w.LastStatus = HOOK_STATUS_SUCCEED
  510. } else {
  511. w.LastStatus = HOOK_STATUS_FAILED
  512. }
  513. if err = UpdateWebhook(w); err != nil {
  514. log.Error(3, "UpdateWebhook: %v", err)
  515. return
  516. }
  517. }()
  518. resp, err := req.Response()
  519. if err != nil {
  520. t.ResponseInfo.Body = fmt.Sprintf("Delivery: %v", err)
  521. return
  522. }
  523. defer resp.Body.Close()
  524. // Status code is 20x can be seen as succeed.
  525. t.IsSucceed = resp.StatusCode/100 == 2
  526. t.ResponseInfo.Status = resp.StatusCode
  527. for k, vals := range resp.Header {
  528. t.ResponseInfo.Headers[k] = strings.Join(vals, ",")
  529. }
  530. p, err := ioutil.ReadAll(resp.Body)
  531. if err != nil {
  532. t.ResponseInfo.Body = fmt.Sprintf("read body: %s", err)
  533. return
  534. }
  535. t.ResponseInfo.Body = string(p)
  536. }
  537. // DeliverHooks checks and delivers undelivered hooks.
  538. // TODO: shoot more hooks at same time.
  539. func DeliverHooks() {
  540. tasks := make([]*HookTask, 0, 10)
  541. x.Where("is_delivered=?", false).Iterate(new(HookTask),
  542. func(idx int, bean interface{}) error {
  543. t := bean.(*HookTask)
  544. t.deliver()
  545. tasks = append(tasks, t)
  546. return nil
  547. })
  548. // Update hook task status.
  549. for _, t := range tasks {
  550. if err := UpdateHookTask(t); err != nil {
  551. log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err)
  552. }
  553. }
  554. // Start listening on new hook requests.
  555. for repoID := range HookQueue.Queue() {
  556. log.Trace("DeliverHooks [repo_id: %v]", repoID)
  557. HookQueue.Remove(repoID)
  558. tasks = make([]*HookTask, 0, 5)
  559. if err := x.Where("repo_id=? AND is_delivered=?", repoID, false).Find(&tasks); err != nil {
  560. log.Error(4, "Get repository [%s] hook tasks: %v", repoID, err)
  561. continue
  562. }
  563. for _, t := range tasks {
  564. t.deliver()
  565. if err := UpdateHookTask(t); err != nil {
  566. log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err)
  567. continue
  568. }
  569. }
  570. }
  571. }
  572. func InitDeliverHooks() {
  573. go DeliverHooks()
  574. }