Method: Rev::HttpClientParser#execute
- Defined in:
- ext/http11_client/http11_client.c
#execute(req_hash, data, start) ⇒ Integer
Takes a Hash and a String of data, parses the String of data filling in the Hash returning an Integer to indicate how much of the data has been read. No matter what the return value, you should call HttpClientParser#finished? and HttpClientParser#error? to figure out if it’s done parsing or there was an error.
This function now throws an exception when there is a parsing error. This makes the logic for working with the parser much easier. You can still test for an error, but now you need to wrap the parser with an exception handling block.
The third argument allows for parsing a partial request and then continuing the parsing from that position. It needs all of the original data as well so you have to append to the data buffer as you read.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'ext/http11_client/http11_client.c', line 204 VALUE HttpClientParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE start) { httpclient_parser *http = NULL; int from = 0; char *dptr = NULL; long dlen = 0; REQUIRE_TYPE(req_hash, T_HASH); REQUIRE_TYPE(data, T_STRING); REQUIRE_TYPE(start, T_FIXNUM); DATA_GET(self, httpclient_parser, http); from = FIX2INT(start); dptr = RSTRING_PTR(data); dlen = RSTRING_LEN(data); if(from >= dlen) { rb_raise(eHttpClientParserError, "Requested start is after data buffer end."); } else { http->data = (void *)req_hash; httpclient_parser_execute(http, dptr, dlen, from); if(httpclient_parser_has_error(http)) { rb_raise(eHttpClientParserError, "Invalid HTTP format, parsing fails."); } else { return INT2FIX(httpclient_parser_nread(http)); } } } |