Class: Nyara::Test::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/nyara/test.rb,
ext/test_response.c

Instance Method Summary collapse

Constructor Details

#initializeObject


104
105
106
107
108
109
110
111
112
113
# File 'ext/test_response.c', line 104

static VALUE response_initialize(VALUE self, VALUE data) {
  Check_Type(data, T_STRING);
  Response* p;
  Data_Get_Struct(self, Response, p);
  p->header = rb_class_new_instance(0, NULL, nyara_header_hash_class);
  p->set_cookies = rb_ary_new();
  p->body = rb_enc_str_new("", 0, u8_encoding);
  http_parser_execute(&(p->hparser), &response_parse_settings, RSTRING_PTR(data), RSTRING_LEN(data));
  return self;
}

Instance Method Details

#bodyObject


121
122
123
124
125
# File 'ext/test_response.c', line 121

static VALUE response_body(VALUE self) {
  Response* p;
  Data_Get_Struct(self, Response, p);
  return p->body;
}

#headerObject


115
116
117
118
119
# File 'ext/test_response.c', line 115

static VALUE response_header(VALUE self) {
  Response* p;
  Data_Get_Struct(self, Response, p);
  return p->header;
}

#redirect_locationObject


10
11
12
13
14
# File 'lib/nyara/test.rb', line 10

def redirect_location
  if HTTP_REDIRECT_STATUS.include?(status)
    header['Location']
  end
end

#set_cookiesObject


133
134
135
136
137
# File 'ext/test_response.c', line 133

static VALUE response_set_cookies(VALUE self) {
  Response* p;
  Data_Get_Struct(self, Response, p);
  return p->set_cookies;
}

#statusObject


127
128
129
130
131
# File 'ext/test_response.c', line 127

static VALUE response_status(VALUE self) {
  Response* p;
  Data_Get_Struct(self, Response, p);
  return INT2FIX(p->hparser.status_code);
}

#success?Boolean

Whether request is success

Returns:

  • (Boolean)

6
7
8
# File 'lib/nyara/test.rb', line 6

def success?
  status < 400
end