input.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. // Copyright 2014 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package context
  15. import (
  16. "bytes"
  17. "errors"
  18. "io"
  19. "io/ioutil"
  20. "net/url"
  21. "reflect"
  22. "regexp"
  23. "strconv"
  24. "strings"
  25. "github.com/astaxie/beego/session"
  26. )
  27. // Regexes for checking the accept headers
  28. // TODO make sure these are correct
  29. var (
  30. acceptsHTMLRegex = regexp.MustCompile(`(text/html|application/xhtml\+xml)(?:,|$)`)
  31. acceptsXMLRegex = regexp.MustCompile(`(application/xml|text/xml)(?:,|$)`)
  32. acceptsJSONRegex = regexp.MustCompile(`(application/json)(?:,|$)`)
  33. maxParam = 50
  34. )
  35. // BeegoInput operates the http request header, data, cookie and body.
  36. // it also contains router params and current session.
  37. type BeegoInput struct {
  38. Context *Context
  39. CruSession session.Store
  40. pnames []string
  41. pvalues []string
  42. data map[interface{}]interface{} // store some values in this context when calling context in filter or controller.
  43. RequestBody []byte
  44. RunMethod string
  45. RunController reflect.Type
  46. }
  47. // NewInput return BeegoInput generated by Context.
  48. func NewInput() *BeegoInput {
  49. return &BeegoInput{
  50. pnames: make([]string, 0, maxParam),
  51. pvalues: make([]string, 0, maxParam),
  52. data: make(map[interface{}]interface{}),
  53. }
  54. }
  55. // Reset init the BeegoInput
  56. func (input *BeegoInput) Reset(ctx *Context) {
  57. input.Context = ctx
  58. input.CruSession = nil
  59. input.pnames = input.pnames[:0]
  60. input.pvalues = input.pvalues[:0]
  61. input.data = nil
  62. input.RequestBody = []byte{}
  63. }
  64. // Protocol returns request protocol name, such as HTTP/1.1 .
  65. func (input *BeegoInput) Protocol() string {
  66. return input.Context.Request.Proto
  67. }
  68. // URI returns full request url with query string, fragment.
  69. func (input *BeegoInput) URI() string {
  70. return input.Context.Request.RequestURI
  71. }
  72. // URL returns request url path (without query string, fragment).
  73. func (input *BeegoInput) URL() string {
  74. return input.Context.Request.URL.Path
  75. }
  76. // Site returns base site url as scheme://domain type.
  77. func (input *BeegoInput) Site() string {
  78. return input.Scheme() + "://" + input.Domain()
  79. }
  80. // Scheme returns request scheme as "http" or "https".
  81. func (input *BeegoInput) Scheme() string {
  82. if scheme := input.Header("X-Forwarded-Proto"); scheme != "" {
  83. return scheme
  84. }
  85. if input.Context.Request.URL.Scheme != "" {
  86. return input.Context.Request.URL.Scheme
  87. }
  88. if input.Context.Request.TLS == nil {
  89. return "http"
  90. }
  91. return "https"
  92. }
  93. // Domain returns host name.
  94. // Alias of Host method.
  95. func (input *BeegoInput) Domain() string {
  96. return input.Host()
  97. }
  98. // Host returns host name.
  99. // if no host info in request, return localhost.
  100. func (input *BeegoInput) Host() string {
  101. if input.Context.Request.Host != "" {
  102. hostParts := strings.Split(input.Context.Request.Host, ":")
  103. if len(hostParts) > 0 {
  104. return hostParts[0]
  105. }
  106. return input.Context.Request.Host
  107. }
  108. return "localhost"
  109. }
  110. // Method returns http request method.
  111. func (input *BeegoInput) Method() string {
  112. return input.Context.Request.Method
  113. }
  114. // Is returns boolean of this request is on given method, such as Is("POST").
  115. func (input *BeegoInput) Is(method string) bool {
  116. return input.Method() == method
  117. }
  118. // IsGet Is this a GET method request?
  119. func (input *BeegoInput) IsGet() bool {
  120. return input.Is("GET")
  121. }
  122. // IsPost Is this a POST method request?
  123. func (input *BeegoInput) IsPost() bool {
  124. return input.Is("POST")
  125. }
  126. // IsHead Is this a Head method request?
  127. func (input *BeegoInput) IsHead() bool {
  128. return input.Is("HEAD")
  129. }
  130. // IsOptions Is this a OPTIONS method request?
  131. func (input *BeegoInput) IsOptions() bool {
  132. return input.Is("OPTIONS")
  133. }
  134. // IsPut Is this a PUT method request?
  135. func (input *BeegoInput) IsPut() bool {
  136. return input.Is("PUT")
  137. }
  138. // IsDelete Is this a DELETE method request?
  139. func (input *BeegoInput) IsDelete() bool {
  140. return input.Is("DELETE")
  141. }
  142. // IsPatch Is this a PATCH method request?
  143. func (input *BeegoInput) IsPatch() bool {
  144. return input.Is("PATCH")
  145. }
  146. // IsAjax returns boolean of this request is generated by ajax.
  147. func (input *BeegoInput) IsAjax() bool {
  148. return input.Header("X-Requested-With") == "XMLHttpRequest"
  149. }
  150. // IsSecure returns boolean of this request is in https.
  151. func (input *BeegoInput) IsSecure() bool {
  152. return input.Scheme() == "https"
  153. }
  154. // IsWebsocket returns boolean of this request is in webSocket.
  155. func (input *BeegoInput) IsWebsocket() bool {
  156. return input.Header("Upgrade") == "websocket"
  157. }
  158. // IsUpload returns boolean of whether file uploads in this request or not..
  159. func (input *BeegoInput) IsUpload() bool {
  160. return strings.Contains(input.Header("Content-Type"), "multipart/form-data")
  161. }
  162. // AcceptsHTML Checks if request accepts html response
  163. func (input *BeegoInput) AcceptsHTML() bool {
  164. return acceptsHTMLRegex.MatchString(input.Header("Accept"))
  165. }
  166. // AcceptsXML Checks if request accepts xml response
  167. func (input *BeegoInput) AcceptsXML() bool {
  168. return acceptsXMLRegex.MatchString(input.Header("Accept"))
  169. }
  170. // AcceptsJSON Checks if request accepts json response
  171. func (input *BeegoInput) AcceptsJSON() bool {
  172. return acceptsJSONRegex.MatchString(input.Header("Accept"))
  173. }
  174. // IP returns request client ip.
  175. // if in proxy, return first proxy id.
  176. // if error, return 127.0.0.1.
  177. func (input *BeegoInput) IP() string {
  178. ips := input.Proxy()
  179. if len(ips) > 0 && ips[0] != "" {
  180. rip := strings.Split(ips[0], ":")
  181. return rip[0]
  182. }
  183. ip := strings.Split(input.Context.Request.RemoteAddr, ":")
  184. if len(ip) > 0 {
  185. if ip[0] != "[" {
  186. return ip[0]
  187. }
  188. }
  189. return "127.0.0.1"
  190. }
  191. // Proxy returns proxy client ips slice.
  192. func (input *BeegoInput) Proxy() []string {
  193. if ips := input.Header("X-Forwarded-For"); ips != "" {
  194. return strings.Split(ips, ",")
  195. }
  196. return []string{}
  197. }
  198. // Referer returns http referer header.
  199. func (input *BeegoInput) Referer() string {
  200. return input.Header("Referer")
  201. }
  202. // Refer returns http referer header.
  203. func (input *BeegoInput) Refer() string {
  204. return input.Referer()
  205. }
  206. // SubDomains returns sub domain string.
  207. // if aa.bb.domain.com, returns aa.bb .
  208. func (input *BeegoInput) SubDomains() string {
  209. parts := strings.Split(input.Host(), ".")
  210. if len(parts) >= 3 {
  211. return strings.Join(parts[:len(parts)-2], ".")
  212. }
  213. return ""
  214. }
  215. // Port returns request client port.
  216. // when error or empty, return 80.
  217. func (input *BeegoInput) Port() int {
  218. parts := strings.Split(input.Context.Request.Host, ":")
  219. if len(parts) == 2 {
  220. port, _ := strconv.Atoi(parts[1])
  221. return port
  222. }
  223. return 80
  224. }
  225. // UserAgent returns request client user agent string.
  226. func (input *BeegoInput) UserAgent() string {
  227. return input.Header("User-Agent")
  228. }
  229. // ParamsLen return the length of the params
  230. func (input *BeegoInput) ParamsLen() int {
  231. return len(input.pnames)
  232. }
  233. // Param returns router param by a given key.
  234. func (input *BeegoInput) Param(key string) string {
  235. for i, v := range input.pnames {
  236. if v == key && i <= len(input.pvalues) {
  237. return input.pvalues[i]
  238. }
  239. }
  240. return ""
  241. }
  242. // Params returns the map[key]value.
  243. func (input *BeegoInput) Params() map[string]string {
  244. m := make(map[string]string)
  245. for i, v := range input.pnames {
  246. if i <= len(input.pvalues) {
  247. m[v] = input.pvalues[i]
  248. }
  249. }
  250. return m
  251. }
  252. // SetParam will set the param with key and value
  253. func (input *BeegoInput) SetParam(key, val string) {
  254. // check if already exists
  255. for i, v := range input.pnames {
  256. if v == key && i <= len(input.pvalues) {
  257. input.pvalues[i] = val
  258. return
  259. }
  260. }
  261. input.pvalues = append(input.pvalues, val)
  262. input.pnames = append(input.pnames, key)
  263. }
  264. // ResetParams clears any of the input's Params
  265. // This function is used to clear parameters so they may be reset between filter
  266. // passes.
  267. func (input *BeegoInput) ResetParams() {
  268. input.pnames = input.pnames[:0]
  269. input.pvalues = input.pvalues[:0]
  270. }
  271. // Query returns input data item string by a given string.
  272. func (input *BeegoInput) Query(key string) string {
  273. if val := input.Param(key); val != "" {
  274. return val
  275. }
  276. if input.Context.Request.Form == nil {
  277. input.Context.Request.ParseForm()
  278. }
  279. return input.Context.Request.Form.Get(key)
  280. }
  281. // Header returns request header item string by a given string.
  282. // if non-existed, return empty string.
  283. func (input *BeegoInput) Header(key string) string {
  284. return input.Context.Request.Header.Get(key)
  285. }
  286. // Cookie returns request cookie item string by a given key.
  287. // if non-existed, return empty string.
  288. func (input *BeegoInput) Cookie(key string) string {
  289. ck, err := input.Context.Request.Cookie(key)
  290. if err != nil {
  291. return ""
  292. }
  293. return ck.Value
  294. }
  295. // Session returns current session item value by a given key.
  296. // if non-existed, return nil.
  297. func (input *BeegoInput) Session(key interface{}) interface{} {
  298. return input.CruSession.Get(key)
  299. }
  300. // CopyBody returns the raw request body data as bytes.
  301. func (input *BeegoInput) CopyBody(MaxMemory int64) []byte {
  302. if input.Context.Request.Body == nil {
  303. return []byte{}
  304. }
  305. safe := &io.LimitedReader{R: input.Context.Request.Body, N: MaxMemory}
  306. requestbody, _ := ioutil.ReadAll(safe)
  307. input.Context.Request.Body.Close()
  308. bf := bytes.NewBuffer(requestbody)
  309. input.Context.Request.Body = ioutil.NopCloser(bf)
  310. input.RequestBody = requestbody
  311. return requestbody
  312. }
  313. // Data return the implicit data in the input
  314. func (input *BeegoInput) Data() map[interface{}]interface{} {
  315. if input.data == nil {
  316. input.data = make(map[interface{}]interface{})
  317. }
  318. return input.data
  319. }
  320. // GetData returns the stored data in this context.
  321. func (input *BeegoInput) GetData(key interface{}) interface{} {
  322. if v, ok := input.data[key]; ok {
  323. return v
  324. }
  325. return nil
  326. }
  327. // SetData stores data with given key in this context.
  328. // This data are only available in this context.
  329. func (input *BeegoInput) SetData(key, val interface{}) {
  330. if input.data == nil {
  331. input.data = make(map[interface{}]interface{})
  332. }
  333. input.data[key] = val
  334. }
  335. // ParseFormOrMulitForm parseForm or parseMultiForm based on Content-type
  336. func (input *BeegoInput) ParseFormOrMulitForm(maxMemory int64) error {
  337. // Parse the body depending on the content type.
  338. if strings.Contains(input.Header("Content-Type"), "multipart/form-data") {
  339. if err := input.Context.Request.ParseMultipartForm(maxMemory); err != nil {
  340. return errors.New("Error parsing request body:" + err.Error())
  341. }
  342. } else if err := input.Context.Request.ParseForm(); err != nil {
  343. return errors.New("Error parsing request body:" + err.Error())
  344. }
  345. return nil
  346. }
  347. // Bind data from request.Form[key] to dest
  348. // like /?id=123&isok=true&ft=1.2&ol[0]=1&ol[1]=2&ul[]=str&ul[]=array&user.Name=astaxie
  349. // var id int beegoInput.Bind(&id, "id") id ==123
  350. // var isok bool beegoInput.Bind(&isok, "isok") isok ==true
  351. // var ft float64 beegoInput.Bind(&ft, "ft") ft ==1.2
  352. // ol := make([]int, 0, 2) beegoInput.Bind(&ol, "ol") ol ==[1 2]
  353. // ul := make([]string, 0, 2) beegoInput.Bind(&ul, "ul") ul ==[str array]
  354. // user struct{Name} beegoInput.Bind(&user, "user") user == {Name:"astaxie"}
  355. func (input *BeegoInput) Bind(dest interface{}, key string) error {
  356. value := reflect.ValueOf(dest)
  357. if value.Kind() != reflect.Ptr {
  358. return errors.New("beego: non-pointer passed to Bind: " + key)
  359. }
  360. value = value.Elem()
  361. if !value.CanSet() {
  362. return errors.New("beego: non-settable variable passed to Bind: " + key)
  363. }
  364. typ := value.Type()
  365. // Get real type if dest define with interface{}.
  366. // e.g var dest interface{} dest=1.0
  367. if value.Kind() == reflect.Interface {
  368. typ = value.Elem().Type()
  369. }
  370. rv := input.bind(key, typ)
  371. if !rv.IsValid() {
  372. return errors.New("beego: reflect value is empty")
  373. }
  374. value.Set(rv)
  375. return nil
  376. }
  377. func (input *BeegoInput) bind(key string, typ reflect.Type) reflect.Value {
  378. if input.Context.Request.Form == nil {
  379. input.Context.Request.ParseForm()
  380. }
  381. rv := reflect.Zero(typ)
  382. switch typ.Kind() {
  383. case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
  384. val := input.Query(key)
  385. if len(val) == 0 {
  386. return rv
  387. }
  388. rv = input.bindInt(val, typ)
  389. case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
  390. val := input.Query(key)
  391. if len(val) == 0 {
  392. return rv
  393. }
  394. rv = input.bindUint(val, typ)
  395. case reflect.Float32, reflect.Float64:
  396. val := input.Query(key)
  397. if len(val) == 0 {
  398. return rv
  399. }
  400. rv = input.bindFloat(val, typ)
  401. case reflect.String:
  402. val := input.Query(key)
  403. if len(val) == 0 {
  404. return rv
  405. }
  406. rv = input.bindString(val, typ)
  407. case reflect.Bool:
  408. val := input.Query(key)
  409. if len(val) == 0 {
  410. return rv
  411. }
  412. rv = input.bindBool(val, typ)
  413. case reflect.Slice:
  414. rv = input.bindSlice(&input.Context.Request.Form, key, typ)
  415. case reflect.Struct:
  416. rv = input.bindStruct(&input.Context.Request.Form, key, typ)
  417. case reflect.Ptr:
  418. rv = input.bindPoint(key, typ)
  419. case reflect.Map:
  420. rv = input.bindMap(&input.Context.Request.Form, key, typ)
  421. }
  422. return rv
  423. }
  424. func (input *BeegoInput) bindValue(val string, typ reflect.Type) reflect.Value {
  425. rv := reflect.Zero(typ)
  426. switch typ.Kind() {
  427. case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
  428. rv = input.bindInt(val, typ)
  429. case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
  430. rv = input.bindUint(val, typ)
  431. case reflect.Float32, reflect.Float64:
  432. rv = input.bindFloat(val, typ)
  433. case reflect.String:
  434. rv = input.bindString(val, typ)
  435. case reflect.Bool:
  436. rv = input.bindBool(val, typ)
  437. case reflect.Slice:
  438. rv = input.bindSlice(&url.Values{"": {val}}, "", typ)
  439. case reflect.Struct:
  440. rv = input.bindStruct(&url.Values{"": {val}}, "", typ)
  441. case reflect.Ptr:
  442. rv = input.bindPoint(val, typ)
  443. case reflect.Map:
  444. rv = input.bindMap(&url.Values{"": {val}}, "", typ)
  445. }
  446. return rv
  447. }
  448. func (input *BeegoInput) bindInt(val string, typ reflect.Type) reflect.Value {
  449. intValue, err := strconv.ParseInt(val, 10, 64)
  450. if err != nil {
  451. return reflect.Zero(typ)
  452. }
  453. pValue := reflect.New(typ)
  454. pValue.Elem().SetInt(intValue)
  455. return pValue.Elem()
  456. }
  457. func (input *BeegoInput) bindUint(val string, typ reflect.Type) reflect.Value {
  458. uintValue, err := strconv.ParseUint(val, 10, 64)
  459. if err != nil {
  460. return reflect.Zero(typ)
  461. }
  462. pValue := reflect.New(typ)
  463. pValue.Elem().SetUint(uintValue)
  464. return pValue.Elem()
  465. }
  466. func (input *BeegoInput) bindFloat(val string, typ reflect.Type) reflect.Value {
  467. floatValue, err := strconv.ParseFloat(val, 64)
  468. if err != nil {
  469. return reflect.Zero(typ)
  470. }
  471. pValue := reflect.New(typ)
  472. pValue.Elem().SetFloat(floatValue)
  473. return pValue.Elem()
  474. }
  475. func (input *BeegoInput) bindString(val string, typ reflect.Type) reflect.Value {
  476. return reflect.ValueOf(val)
  477. }
  478. func (input *BeegoInput) bindBool(val string, typ reflect.Type) reflect.Value {
  479. val = strings.TrimSpace(strings.ToLower(val))
  480. switch val {
  481. case "true", "on", "1":
  482. return reflect.ValueOf(true)
  483. }
  484. return reflect.ValueOf(false)
  485. }
  486. type sliceValue struct {
  487. index int // Index extracted from brackets. If -1, no index was provided.
  488. value reflect.Value // the bound value for this slice element.
  489. }
  490. func (input *BeegoInput) bindSlice(params *url.Values, key string, typ reflect.Type) reflect.Value {
  491. maxIndex := -1
  492. numNoIndex := 0
  493. sliceValues := []sliceValue{}
  494. for reqKey, vals := range *params {
  495. if !strings.HasPrefix(reqKey, key+"[") {
  496. continue
  497. }
  498. // Extract the index, and the index where a sub-key starts. (e.g. field[0].subkey)
  499. index := -1
  500. leftBracket, rightBracket := len(key), strings.Index(reqKey[len(key):], "]")+len(key)
  501. if rightBracket > leftBracket+1 {
  502. index, _ = strconv.Atoi(reqKey[leftBracket+1 : rightBracket])
  503. }
  504. subKeyIndex := rightBracket + 1
  505. // Handle the indexed case.
  506. if index > -1 {
  507. if index > maxIndex {
  508. maxIndex = index
  509. }
  510. sliceValues = append(sliceValues, sliceValue{
  511. index: index,
  512. value: input.bind(reqKey[:subKeyIndex], typ.Elem()),
  513. })
  514. continue
  515. }
  516. // It's an un-indexed element. (e.g. element[])
  517. numNoIndex += len(vals)
  518. for _, val := range vals {
  519. // Unindexed values can only be direct-bound.
  520. sliceValues = append(sliceValues, sliceValue{
  521. index: -1,
  522. value: input.bindValue(val, typ.Elem()),
  523. })
  524. }
  525. }
  526. resultArray := reflect.MakeSlice(typ, maxIndex+1, maxIndex+1+numNoIndex)
  527. for _, sv := range sliceValues {
  528. if sv.index != -1 {
  529. resultArray.Index(sv.index).Set(sv.value)
  530. } else {
  531. resultArray = reflect.Append(resultArray, sv.value)
  532. }
  533. }
  534. return resultArray
  535. }
  536. func (input *BeegoInput) bindStruct(params *url.Values, key string, typ reflect.Type) reflect.Value {
  537. result := reflect.New(typ).Elem()
  538. fieldValues := make(map[string]reflect.Value)
  539. for reqKey, val := range *params {
  540. var fieldName string
  541. if strings.HasPrefix(reqKey, key+".") {
  542. fieldName = reqKey[len(key)+1:]
  543. } else if strings.HasPrefix(reqKey, key+"[") && reqKey[len(reqKey)-1] == ']' {
  544. fieldName = reqKey[len(key)+1 : len(reqKey)-1]
  545. } else {
  546. continue
  547. }
  548. if _, ok := fieldValues[fieldName]; !ok {
  549. // Time to bind this field. Get it and make sure we can set it.
  550. fieldValue := result.FieldByName(fieldName)
  551. if !fieldValue.IsValid() {
  552. continue
  553. }
  554. if !fieldValue.CanSet() {
  555. continue
  556. }
  557. boundVal := input.bindValue(val[0], fieldValue.Type())
  558. fieldValue.Set(boundVal)
  559. fieldValues[fieldName] = boundVal
  560. }
  561. }
  562. return result
  563. }
  564. func (input *BeegoInput) bindPoint(key string, typ reflect.Type) reflect.Value {
  565. return input.bind(key, typ.Elem()).Addr()
  566. }
  567. func (input *BeegoInput) bindMap(params *url.Values, key string, typ reflect.Type) reflect.Value {
  568. var (
  569. result = reflect.MakeMap(typ)
  570. keyType = typ.Key()
  571. valueType = typ.Elem()
  572. )
  573. for paramName, values := range *params {
  574. if !strings.HasPrefix(paramName, key+"[") || paramName[len(paramName)-1] != ']' {
  575. continue
  576. }
  577. key := paramName[len(key)+1 : len(paramName)-1]
  578. result.SetMapIndex(input.bindValue(key, keyType), input.bindValue(values[0], valueType))
  579. }
  580. return result
  581. }