Navigation Menu

Skip to content

Commit

Permalink
Treat all HTTP requests under /d/ path is API request
Browse files Browse the repository at this point in the history
Before:

/d/nonexistent-command returns a file content at
${DOCUMENT_ROOT}/d/nonexistent-command.

After:

/d/nonexistent-command returns '[[-22, 0.0, 0.0], "invalid command
name: nonexistent-command"]'.

Both groonga --protocol http and groonga-httpd are changed.
  • Loading branch information
kou committed Apr 30, 2014
1 parent c10e9e3 commit 24ca9b0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/ctx.c
Expand Up @@ -1651,9 +1651,11 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len)
if (!GRN_TEXT_LEN(&buf)) { GRN_TEXT_SETS(ctx, &buf, INDEX_HTML); }
v = GRN_TEXT_VALUE(&buf);
grn_str_get_mime_type(ctx, v, GRN_BULK_CURR(&buf), &key_end, &filename_end);
if ((GRN_TEXT_LEN(&buf) >= 2 && v[0] == 'd' && v[1] == '/') &&
(expr = grn_ctx_get(ctx, v + 2, key_end - (v + 2))) &&
command_proc_p(expr)) {
if ((GRN_TEXT_LEN(&buf) >= 2 && v[0] == 'd' && v[1] == '/')) {
const char *command_name = v + 2;
int command_name_size = key_end - command_name;
expr = grn_ctx_get(ctx, command_name, command_name_size);
if (expr && command_proc_p(expr)) {
while (p < e) {
int l;
GRN_BULK_REWIND(&buf);
Expand Down Expand Up @@ -1681,6 +1683,10 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len)
}
ctx->impl->curr_expr = expr;
grn_expr_exec(ctx, expr, 0);
} else {
ERR(GRN_INVALID_ARGUMENT, "invalid command name: %.*s",
command_name_size, command_name);
}
} else if ((expr = grn_ctx_get(ctx, GRN_EXPR_MISSING_NAME,
strlen(GRN_EXPR_MISSING_NAME)))) {
if ((val = grn_expr_get_var_by_offset(ctx, expr, 0))) {
Expand Down

0 comments on commit 24ca9b0

Please sign in to comment.