Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progressive response from mruby #645

Merged
merged 8 commits into from
Dec 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ IF (WITH_MRUBY)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mruby)
LIST(APPEND STANDALONE_SOURCE_FILES
lib/handler/mruby.c
lib/handler/mruby/chunked.c
lib/handler/mruby/http_request.c
lib/handler/configurator/mruby.c)
SET(STANDALONE_COMPILE_FLAGS "${STANDALONE_COMPILE_FLAGS} -DH2O_USE_MRUBY=1")
Expand Down
4 changes: 4 additions & 0 deletions h2o.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
100A55101C2BB15600C4E3E0 /* http_request.c in Sources */ = {isa = PBXBuildFile; fileRef = 100A550E1C2BB15100C4E3E0 /* http_request.c */; };
100A55151C30C5BC00C4E3E0 /* chunked.c in Sources */ = {isa = PBXBuildFile; fileRef = 100A55141C30C5BC00C4E3E0 /* chunked.c */; };
101788B219B561AA0084C6D8 /* socket.c in Sources */ = {isa = PBXBuildFile; fileRef = 101788B119B561AA0084C6D8 /* socket.c */; };
101B670C19ADD3380084A351 /* access_log.c in Sources */ = {isa = PBXBuildFile; fileRef = 101B670B19ADD3380084A351 /* access_log.c */; };
103BAB361B130666000694F4 /* socket.c in Sources */ = {isa = PBXBuildFile; fileRef = 103BAB351B130666000694F4 /* socket.c */; };
Expand Down Expand Up @@ -270,6 +271,7 @@
100A550C1C22857B00C4E3E0 /* 50mruby-htpasswd.t */ = {isa = PBXFileReference; lastKnownFileType = text; path = "50mruby-htpasswd.t"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.perl; };
100A550E1C2BB15100C4E3E0 /* http_request.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = http_request.c; sourceTree = "<group>"; };
100A55131C2E5FAC00C4E3E0 /* 50mruby-http-request.t */ = {isa = PBXFileReference; lastKnownFileType = text; path = "50mruby-http-request.t"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.perl; };
100A55141C30C5BC00C4E3E0 /* chunked.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = chunked.c; sourceTree = "<group>"; };
100AE41A1B27D74800CE18BB /* 50file-range.t */ = {isa = PBXFileReference; lastKnownFileType = text; path = "50file-range.t"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.perl; };
101788B119B561AA0084C6D8 /* socket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = socket.c; sourceTree = "<group>"; };
101B670B19ADD3380084A351 /* access_log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = access_log.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -587,6 +589,7 @@
100A550D1C2BB12A00C4E3E0 /* mruby */ = {
isa = PBXGroup;
children = (
100A55141C30C5BC00C4E3E0 /* chunked.c */,
100A550E1C2BB15100C4E3E0 /* http_request.c */,
);
path = mruby;
Expand Down Expand Up @@ -1629,6 +1632,7 @@
files = (
107D4D4F1B58970D004A9B21 /* ssl.c in Sources */,
10756E2C1AC126420009BF57 /* emitter.c in Sources */,
100A55151C30C5BC00C4E3E0 /* chunked.c in Sources */,
100A55101C2BB15600C4E3E0 /* http_request.c in Sources */,
10756E2A1AC126420009BF57 /* api.c in Sources */,
10756E2B1AC126420009BF57 /* dumper.c in Sources */,
Expand Down
68 changes: 63 additions & 5 deletions include/h2o/mruby_.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@

#define H2O_MRUBY_MODULE_NAME "h2o_mruby"

enum {
H2O_MRUBY_LIT_REQUEST_METHOD = H2O_MAX_TOKENS,
H2O_MRUBY_LIT_SCRIPT_NAME,
H2O_MRUBY_LIT_PATH_INFO,
H2O_MRUBY_LIT_QUERY_STRING,
H2O_MRUBY_LIT_SERVER_NAME,
H2O_MRUBY_LIT_SERVER_ADDR,
H2O_MRUBY_LIT_SERVER_PORT,
H2O_MRUBY_LIT_CONTENT_LENGTH,
H2O_MRUBY_LIT_REMOTE_ADDR,
H2O_MRUBY_LIT_REMOTE_PORT,
H2O_MRUBY_LIT_RACK_URL_SCHEME,
H2O_MRUBY_LIT_RACK_MULTITHREAD,
H2O_MRUBY_LIT_RACK_MULTIPROCESS,
H2O_MRUBY_LIT_RACK_RUN_ONCE,
H2O_MRUBY_LIT_RACK_HIJACK_,
H2O_MRUBY_LIT_RACK_INPUT,
H2O_MRUBY_LIT_RACK_ERRORS,
H2O_MRUBY_LIT_SERVER_SOFTWARE,
H2O_MRUBY_LIT_SERVER_SOFTWARE_VALUE,
H2O_MRUBY_PROC_EACH_TO_ARRAY,
H2O_MRUBY_PROC_APP_TO_FIBER,

/* used by chunked.c */
H2O_MRUBY_CHUNKED_PROC_EACH_TO_FIBER,

/* used by http_request.c */
H2O_MRUBY_HTTP_REQUEST_INPUT_STREAM_CLASS,

H2O_MRUBY_NUM_CONSTANTS
};

typedef struct st_h2o_mruby_config_vars_t {
h2o_iovec_t source;
char *path;
Expand All @@ -30,31 +62,57 @@ typedef struct st_h2o_mruby_context_t {
} symbols;
} h2o_mruby_context_t;

typedef struct st_h2o_mruby_chunked_t h2o_mruby_chunked_t;
typedef struct st_h2o_mruby_generator_t {
h2o_generator_t super;
h2o_req_t *req;/* becomes NULL once the underlying connection gets terminated */
h2o_mruby_context_t *ctx;
mrb_value rack_input;
mrb_value receiver;
struct {
void (*cb)(struct st_h2o_mruby_generator_t *);
void *data;
} async_dispose;
h2o_mruby_chunked_t *chunked;
} h2o_mruby_generator_t;

#define H2O_MRUBY_CALLBACK_ID_EXCEPTION_RAISED -1 /* used to notify exception, does not execution to mruby code */
#define H2O_MRUBY_CALLBACK_ID_HTTP_REQUEST -2
#define H2O_MRUBY_CALLBACK_ID_SEND_BODY_CHUNK -2
#define H2O_MRUBY_CALLBACK_ID_HTTP_REQUEST -3
#define H2O_MRUBY_CALLBACK_ID_HTTP_REQUEST_FETCH_CHUNK -4

enum {
H2O_MRUBY_CALLBACK_NEXT_ACTION_STOP,
H2O_MRUBY_CALLBACK_NEXT_ACTION_IMMEDIATE,
H2O_MRUBY_CALLBACK_NEXT_ACTION_ASYNC
};

#define h2o_mruby_assert(mrb) \
if (mrb->exc != NULL) \
h2o_mruby__assert_failed(mrb, __FILE__, __LINE__)

/* handler/mruby.c */
mrb_value h2o_mruby_compile_code(mrb_state *mrb_state, h2o_mruby_config_vars_t *config, char *errbuf);
void h2o_mruby__assert_failed(mrb_state *mrb, const char *file, int line);
mrb_value h2o_mruby_eval_expr(mrb_state *mrb, const char *expr);
void h2o_mruby_define_callback(mrb_state *mrb, const char *name, int id);
mrb_value h2o_mruby_compile_code(mrb_state *mrb, h2o_mruby_config_vars_t *config, char *errbuf);
h2o_mruby_handler_t *h2o_mruby_register(h2o_pathconf_t *pathconf, h2o_mruby_config_vars_t *config);
void h2o_mruby_run_fiber(h2o_mruby_generator_t *generator, mrb_value input, int gc_arena, int *is_delegate);
void h2o_mruby_run_fiber(h2o_mruby_generator_t *generator, mrb_value receiver, mrb_value input, int gc_arena, int *is_delegate);
mrb_value h2o_mruby_each_to_array(h2o_mruby_context_t *handler_ctx, mrb_value src);
int h2o_mruby_iterate_headers(h2o_mruby_context_t *handler_ctx, mrb_value headers,
int (*cb)(h2o_mruby_context_t *, h2o_iovec_t, h2o_iovec_t, void *), void *cb_data);

/* handler/mruby/chunked.c */
void h2o_mruby_send_chunked_init_context(h2o_mruby_context_t *ctx);
void h2o_mruby_send_chunked_errorclose(h2o_mruby_generator_t *generator);
mrb_value h2o_mruby_send_chunked_init(h2o_mruby_generator_t *generator);
void h2o_mruby_send_chunked_dispose(h2o_mruby_generator_t *generator);
mrb_value h2o_mruby_send_chunked_callback(h2o_mruby_generator_t *generator, mrb_value receiver, mrb_value input, int *next_action);

/* handler/mruby/http_request.c */
mrb_value h2o_mruby_http_request_callback(h2o_mruby_generator_t *generator, mrb_value input);
void h2o_mruby_http_request_init_context(h2o_mruby_context_t *ctx);
mrb_value h2o_mruby_http_request_callback(h2o_mruby_generator_t *generator, mrb_value receiver, mrb_value input, int *next_action);
mrb_value h2o_mruby_http_request_fetch_chunk_callback(h2o_mruby_generator_t *generator, mrb_value receiver, mrb_value input,
int *next_action);

/* handler/configurator/mruby.c */
void h2o_mruby_register_configurator(h2o_globalconf_t *conf);
Expand Down
Loading