1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 #ifndef AWS_JNI_CRT_HTTP_REQUEST_RESPONSE_H 7 #define AWS_JNI_CRT_HTTP_REQUEST_RESPONSE_H 8 9 #include <aws/http/request_response.h> 10 #include <jni.h> 11 12 struct aws_http_message; 13 struct aws_http_stream; 14 struct aws_byte_buf; 15 struct aws_atomic_var; 16 17 struct http_stream_binding { 18 JavaVM *jvm; 19 20 // TEMP: Until Java API changes to match "H1B" native HTTP API, 21 // create aws_http_message and aws_input_stream under the hood. 22 struct aws_http_message *native_request; 23 24 jobject java_http_response_stream_handler; 25 jobject java_http_stream_base; 26 struct aws_http_stream *native_stream; 27 struct aws_byte_buf headers_buf; 28 int response_status; 29 /* For the native http stream and the Java stream object */ 30 struct aws_atomic_var ref; 31 }; 32 33 jobject aws_java_http_stream_from_native_new(JNIEnv *env, void *opaque, int version); 34 void aws_java_http_stream_from_native_delete(JNIEnv *env, jobject jHttpStream); 35 36 void *aws_http_stream_binding_release(JNIEnv *env, struct http_stream_binding *binding); 37 void *aws_http_stream_binding_acquire(struct http_stream_binding *binding); 38 39 // If error occurs, A Java exception is thrown and NULL is returned. 40 struct http_stream_binding *aws_http_stream_binding_new(JNIEnv *env, jobject java_callback_handler); 41 42 /* Default callbacks using binding */ 43 int aws_java_http_stream_on_incoming_headers_fn( 44 struct aws_http_stream *stream, 45 enum aws_http_header_block block_type, 46 const struct aws_http_header *header_array, 47 size_t num_headers, 48 void *user_data); 49 int aws_java_http_stream_on_incoming_header_block_done_fn( 50 struct aws_http_stream *stream, 51 enum aws_http_header_block block_type, 52 void *user_data); 53 int aws_java_http_stream_on_incoming_body_fn( 54 struct aws_http_stream *stream, 55 const struct aws_byte_cursor *data, 56 void *user_data); 57 void aws_java_http_stream_on_stream_complete_fn(struct aws_http_stream *stream, int error_code, void *user_data); 58 void aws_java_http_stream_on_stream_destroy_fn(void *user_data); 59 60 #endif /* AWS_JNI_CRT_HTTP_REQUEST_RESPONSE_H */ 61