Пример #1
0
//export reqBody
func reqBody(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	if req.Body == nil {
		return C.Qnil
	}
	return goioNew(rb_cGoIO, req.Body)
}
Пример #2
0
//export respBody
func respBody(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	if resp.Body == nil {
		return C.Qnil
	}
	return goioNew(rb_cGoIO, resp.Body)
}
Пример #3
0
//export respHeader
func respHeader(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	h := C.rb_hash_new()
	for key, value := range resp.Header {
		C.rb_hash_aset(h, RbString(key), StrSlice2RbArray(value))
	}
	return h
}
Пример #4
0
//export goioClose
func goioClose(self C.VALUE) C.VALUE {
	v := (*reflect.Value)(C.GetGoStruct(self))
	if c, ok := v.Interface().(io.Closer); ok {
		c.Close()
		return C.Qtrue
	}
	return C.Qfalse
}
Пример #5
0
//export goioRead
func goioRead(self C.VALUE) C.VALUE {
	v := (*reflect.Value)(C.GetGoStruct(self))
	r := v.Interface().(io.Reader)
	body, err := ioutil.ReadAll(r)
	if err != nil {
		rb_raise(C.rb_eArgError, "'%s'", err)
	}
	return RbBytes(body)
}
Пример #6
0
//export goio_to_s
func goio_to_s(self C.VALUE) C.VALUE {
	v := (*reflect.Value)(C.GetGoStruct(self))
	switch v.Kind() {
	case reflect.Struct:
		return RbString(fmt.Sprintf("#<GoIO:%s>", v.Type().String()))
	case reflect.Chan, reflect.Map, reflect.Ptr, reflect.UnsafePointer:
		return RbString(fmt.Sprintf("#<GoIO:%s:0x%X>", v.Type().String(), v.Pointer()))
	default:
		return RbString(fmt.Sprintf("#<GoIO:%s>", v.Type().String()))
	}
}
Пример #7
0
//export reqProto
func reqProto(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return RbString(req.Proto)
}
Пример #8
0
//export respRequest
func respRequest(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return reqNew(rb_cRequest, resp.Request)
}
Пример #9
0
//export respProto
func respProto(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return RbString(resp.Proto)
}
Пример #10
0
//export respTransferEncoding
func respTransferEncoding(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return StrSlice2RbArray(resp.TransferEncoding)
}
Пример #11
0
//export respStatus
func respStatus(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return RbString(resp.Status)
}
Пример #12
0
//export respStatusCode
func respStatusCode(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return INT2NUM(resp.StatusCode)
}
Пример #13
0
//export reqMethod
func reqMethod(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return RbString(req.Method)
}
Пример #14
0
//export respContentLength
func respContentLength(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return INT64toNUM(resp.ContentLength)
}
Пример #15
0
//export reqRequestURI
func reqRequestURI(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return RbString(req.RequestURI)
}
Пример #16
0
//export reqTransferEncoding
func reqTransferEncoding(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return StrSlice2RbArray(req.TransferEncoding)
}
Пример #17
0
//export reqContentLength
func reqContentLength(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return INT64toNUM(req.ContentLength)
}