From d96e3949471b42bd4e994bd1c2a200eebab77c60 Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 6 Mar 2013 12:25:09 +0100 Subject: [PATCH] implemented ring content-length --- plugins/jvm/jvm.h | 1 + plugins/jvm/jvm_plugin.c | 12 ++++++++++++ plugins/ring/ring_plugin.c | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/plugins/jvm/jvm.h b/plugins/jvm/jvm.h index ec90a353..04133101 100644 --- a/plugins/jvm/jvm.h +++ b/plugins/jvm/jvm.h @@ -87,3 +87,4 @@ void uwsgi_jvm_local_unref(jobject); int uwsgi_jvm_call_bool(jobject, jmethodID, ...); int uwsgi_jvm_consume_input_stream(struct wsgi_request *, size_t, jobject); +jobject uwsgi_jvm_num(long); diff --git a/plugins/jvm/jvm_plugin.c b/plugins/jvm/jvm_plugin.c index 125c4308..aafe2344 100644 --- a/plugins/jvm/jvm_plugin.c +++ b/plugins/jvm/jvm_plugin.c @@ -382,6 +382,18 @@ jobject uwsgi_jvm_iterator_next(jobject iterator) { return uwsgi_jvm_call_object(iterator, mid); } +jobject uwsgi_jvm_num(long num) { + static jmethodID mid = 0; + if (!mid) { + mid = uwsgi_jvm_get_method_id(ujvm.int_class, "", "(I)V"); + if (!mid) return NULL; + } + jobject o = (*ujvm_env)->NewObject(ujvm_env, ujvm.int_class, mid, num); + if (uwsgi_jvm_exception()) { + return NULL; + } + return o; +} jobject uwsgi_jvm_str(char *str, size_t len) { jobject new_str; diff --git a/plugins/ring/ring_plugin.c b/plugins/ring/ring_plugin.c index 8c4fef0d..4105ab73 100644 --- a/plugins/ring/ring_plugin.c +++ b/plugins/ring/ring_plugin.c @@ -117,6 +117,23 @@ static int uwsgi_ring_request_item_add_keyword(jobject hm, char *key, size_t key return ret; } +static int uwsgi_ring_request_item_add_num(jobject hm, char *key, size_t keylen, long num) { + jobject j_key = uwsgi_ring_keyword(key, keylen); + if (!j_key) return -1; + + jobject j_value = uwsgi_jvm_num(num); + if (!j_value) { + uwsgi_jvm_local_unref(j_key); + return -1; + } + + int ret = uwsgi_jvm_hashmap_put(hm, j_key, j_value); + uwsgi_jvm_local_unref(j_key); + uwsgi_jvm_local_unref(j_value); + return ret; +} + + // get the iterator from an Associative object static jobject uwsgi_ring_Associative_iterator(jobject o) { @@ -181,6 +198,10 @@ static int uwsgi_ring_request(struct wsgi_request *wsgi_req) { if (uwsgi_ring_request_item_add(hm, "content-type", 12, wsgi_req->content_type, wsgi_req->content_type_len)) goto end; } + if (wsgi_req->post_cl > 0) { + if (uwsgi_ring_request_item_add_num(hm, "content-length", 14, wsgi_req->post_cl)) goto end; + } + // convert the HashMap to Associative request = uwsgi_ring_invoke2(uring.into, empty_request, hm); if (!request) goto end;