Esempio n. 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)
}
Esempio n. 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)
}
Esempio n. 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
}
Esempio n. 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
}
Esempio n. 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)
}
Esempio n. 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()))
	}
}
Esempio n. 7
0
//export reqProto
func reqProto(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return RbString(req.Proto)
}
Esempio n. 8
0
//export respRequest
func respRequest(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return reqNew(rb_cRequest, resp.Request)
}
Esempio n. 9
0
//export respProto
func respProto(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return RbString(resp.Proto)
}
Esempio n. 10
0
//export respTransferEncoding
func respTransferEncoding(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return StrSlice2RbArray(resp.TransferEncoding)
}
Esempio n. 11
0
//export respStatus
func respStatus(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return RbString(resp.Status)
}
Esempio n. 12
0
//export respStatusCode
func respStatusCode(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return INT2NUM(resp.StatusCode)
}
Esempio n. 13
0
//export reqMethod
func reqMethod(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return RbString(req.Method)
}
Esempio n. 14
0
//export respContentLength
func respContentLength(self C.VALUE) C.VALUE {
	resp := (*http.Response)(C.GetGoStruct(self))
	return INT64toNUM(resp.ContentLength)
}
Esempio n. 15
0
//export reqRequestURI
func reqRequestURI(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return RbString(req.RequestURI)
}
Esempio n. 16
0
//export reqTransferEncoding
func reqTransferEncoding(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return StrSlice2RbArray(req.TransferEncoding)
}
Esempio n. 17
0
//export reqContentLength
func reqContentLength(self C.VALUE) C.VALUE {
	req := (*http.Request)(C.GetGoStruct(self))
	return INT64toNUM(req.ContentLength)
}