sfml3.rb

Class: SFML::Http

Inherits:
Object
  • Object
show all
Defined in:
ext/network/http.c,
ext/network/http.c

Overview

A basic HTTP client for performing requests against one host at a time (set with #set_host).

Instance Method Summary collapse

Constructor Details

#new ⇒ Http

Creates a new HTTP client with no host set.



122
123
124
# File 'ext/network/http.c', line 122

static VALUE Http_initialize(VALUE self) {
    return self;
}

Instance Method Details

#send_request(request, timeout = Time.zero) ⇒ HttpResponse

Sends request to the host set with #set_host, blocking until the response arrives or timeout elapses.

Returns:

Returns:

Raises:

  • (TypeError) —

    if request is not an SFML::HttpRequest



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/network/http.c', line 150

static VALUE Http_send_request(int argc, VALUE* argv, VALUE self) {
    VALUE rb_request, rb_timeout;
    sfTime timeout = sfTime_Zero;

    rb_scan_args(argc, argv, "11", &rb_request, &rb_timeout);

    if (!rb_obj_is_kind_of(rb_request, rb_cHttpRequest)) {
        rb_raise(rb_eTypeError, "expected an SFML::HttpRequest");
    }

    if (!NIL_P(rb_timeout)) {
        timeout = time_from_rb(rb_timeout);
    }

    return HttpResponse_wrap(
        sfHttp_sendRequest(Get_Http_Struct(self), Get_HttpRequest_Struct(rb_request), timeout));
}

#set_host(host, port = 0) ⇒ self

Sets the target host of subsequent requests. port of 0 means the standard port for the scheme (80 for HTTP, 443 for HTTPS) is used; host may include a scheme, e.g. "https://example.com".

Returns:

  • (self)

Returns:

  • (self)


135
136
137
138
139
# File 'ext/network/http.c', line 135

static VALUE Http_set_host(VALUE self, VALUE rb_host, VALUE rb_port) {
    sfHttp_setHost(Get_Http_Struct(self), StringValueCStr(rb_host),
                   (unsigned short)NUM2INT(rb_port));
    return self;
}