Skip to content

Commit

Permalink
response http
Browse files Browse the repository at this point in the history
  • Loading branch information
covrom committed Oct 30, 2017
1 parent 9c60a3b commit c88b3da
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions core/corehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,39 @@ func (x *VMHttpResponse) Send(status VMInt, b VMString, h VMStringMap) error {
return nil
}

func (x *VMHttpResponse) RequestAsVMStringMap() (VMStringMap, error) {

var err error
rmap := make(VMStringMap)

rmap["Тело"], err = x.ReadBody()
if err != nil {
return rmap, err
}

rmap["ДлинаКонтента"] = VMInt(x.r.ContentLength)
rmap["Статус"] = VMInt(x.r.StatusCode)

m1 := make(VMStringMap)
for k, v := range x.r.Header {
if len(v) > 0 {
m1[k] = VMString(v[0])
}
}
rmap["Заголовки"] = m1

return rmap, nil
}

func (x *VMHttpResponse) MethodMember(name int) (VMFunc, bool) {

// только эти методы будут доступны из кода на языке Гонец!

switch names.UniqueNames.GetLowerCase(name) {
case "отправить":
return VMFuncMustParams(1, x.Отправить), true
case "тело":
return VMFuncMustParams(0, x.Тело), true
case "сообщение":
return VMFuncMustParams(0, x.Сообщение), true
}

return nil, false
Expand Down Expand Up @@ -344,8 +368,11 @@ func (x *VMHttpResponse) Отправить(args VMSlice, rets *VMSlice, envout
return x.Send(sts, b, h)
}

func (x *VMHttpResponse) Тело(args VMSlice, rets *VMSlice, envout *(*Env)) error {
s, _ := x.ReadBody()
rets.Append(VMString(s))
func (x *VMHttpResponse) Сообщение(args VMSlice, rets *VMSlice, envout *(*Env)) error {
v, err := x.RequestAsVMStringMap()
if err != nil {
return err
}
rets.Append(v)
return nil
}
}

0 comments on commit c88b3da

Please sign in to comment.