0
-static void response_send_status(connection_t *c, const int status)
0
- buffer_t *buf = &c->write_buffer;
0
- char *status_line = get_status_line(status);
0
- #define RESP_HTTP_VERSION "HTTP/1.1 "
0
- buffer_append(buf, RESP_HTTP_VERSION, sizeof(RESP_HTTP_VERSION) - 1);
0
- buffer_append(buf, status_line, strlen(status_line));
0
- buffer_append(buf, CRLF, sizeof(CRLF) - 1);
0
-static void response_send_headers(connection_t *c, VALUE headers)
0
- buffer_t *buf = &c->write_buffer;
0
- VALUE hash, keys, key, value;
0
- #define HEADER_SEP ": "
0
- keys = rb_funcall(headers, sInternedKeys, 0);
0
- /* FIXME very big response header will cause buffer to be stored in tmpfile */
0
- for (i = 0; i < RARRAY_LEN(keys); ++i) {
0
- key = RARRAY_PTR(keys)[i];
0
- value = rb_hash_aref(headers, key);
0
- buffer_append(buf, RSTRING_PTR(key), RSTRING_LEN(key));
0
- buffer_append(buf, HEADER_SEP, sizeof(HEADER_SEP) - 1);
0
- buffer_append(buf, RSTRING_PTR(value), RSTRING_LEN(value));
0
- buffer_append(buf, CRLF, sizeof(CRLF) - 1);
0
- buffer_append(buf, CRLF, sizeof(CRLF) - 1);
0
static void response_send_chunk(connection_t *c, const char *ptr, size_t len)
0
/* chunk too big, split it in smaller chunks and send each separately */
0
@@ -65,6 +30,54 @@ static void response_send_chunk(connection_t *c, const char *ptr, size_t len)
0
+static void response_send_status(connection_t *c, const int status)
0
+ buffer_t *buf = &c->write_buffer;
0
+ char *status_line = get_status_line(status);
0
+ buffer_append(buf, RESP_HTTP_VERSION, sizeof(RESP_HTTP_VERSION) - 1);
0
+ buffer_append(buf, status_line, strlen(status_line));
0
+ buffer_append(buf, CRLF, sizeof(CRLF) - 1);
0
+static VALUE iter_header(VALUE value, VALUE *args)
0
+ connection_t *c = (connection_t *) args[0];
0
+ VALUE key = (VALUE) args[1];
0
+ response_send_chunk(c, RSTRING_PTR(key), RSTRING_LEN(key));
0
+ response_send_chunk(c, HEADER_SEP, sizeof(HEADER_SEP) - 1);
0
+ /* if value ends w/ line break w/ chomp it! */
0
+ size_t len = RSTRING_LEN(value);
0
+ if (RSTRING_PTR(value)[RSTRING_LEN(value) - 1] == '\n')
0
+ response_send_chunk(c, RSTRING_PTR(value), len);
0
+ response_send_chunk(c, CRLF, sizeof(CRLF) - 1);
0
+static void response_send_headers(connection_t *c, VALUE headers)
0
+ VALUE hash, keys, key, value;
0
+ keys = rb_funcall(headers, sInternedKeys, 0);
0
+ for (i = 0; i < RARRAY_LEN(keys); ++i) {
0
+ key = RARRAY_PTR(keys)[i];
0
+ value = rb_hash_aref(headers, key);
0
+ VALUE args[2] = { (VALUE) c, key };
0
+ rb_iterate(rb_each, value, iter_header, (VALUE) args);
0
+ response_send_chunk(c, CRLF, sizeof(CRLF) - 1);
0
static VALUE iter_body(VALUE chunk, VALUE *val_conn)
0
connection_t *c = (connection_t *) val_conn;
Comments
No one has commented yet.