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