Permalink
Browse files

now have a varable for setting the date header

  • Loading branch information...
1 parent da30f9f commit be0a1643f6f9d67980ea32df078c8b5f8a84b0fc @anomalizer committed Dec 26, 2010
Showing with 45 additions and 13 deletions.
  1. +45 −13 ngx_http_aws_auth.c
View
@@ -3,6 +3,7 @@
#include <ngx_http.h>
#define AWS_S3_VARIABLE "s3_auth_token"
+#define AWS_DATE_VARIABLE "aws_date"
static void* ngx_http_aws_auth_create_loc_conf(ngx_conf_t *cf);
static char* ngx_http_aws_auth_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
@@ -33,7 +34,7 @@ static ngx_command_t ngx_http_aws_auth_commands[] = {
};
static ngx_http_module_t ngx_http_aws_auth_module_ctx = {
- register_variable, /* preconfiguration */
+ register_variable, /* preconfiguration */
NULL, /* postconfiguration */
NULL, /* create main configuration */
@@ -93,31 +94,62 @@ static ngx_int_t
ngx_http_aws_auth_variable_s3(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
{
- v->len = 4;
- v->data = ngx_palloc(r->pool, v->len);
- memcpy(v->data, AWS_S3_VARIABLE, v->len);
+
+
+ // TODO get the real stuff going
+ v->len = ngx_cached_http_time.len;
+ // v->data = ngx_palloc(r->pool, v->len);
+ //memcpy(v->data, ngx_cached_http_time.data, v->len);
+ v->data = ngx_cached_http_time.data;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ return NGX_OK;
+}
+
+static ngx_int_t
+ngx_http_aws_auth_variable_date(ngx_http_request_t *r, ngx_http_variable_value_t *v,
+ uintptr_t data)
+{
+
+
+ // TODO get the real stuff going
+ v->len = ngx_cached_http_time.len;
+ // v->data = ngx_palloc(r->pool, v->len);
+ //memcpy(v->data, ngx_cached_http_time.data, v->len);
+ v->data = ngx_cached_http_time.data;
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
return NGX_OK;
}
+static ngx_http_variable_t ngx_http_aws_auth_vars[] = {
+ { ngx_string(AWS_S3_VARIABLE), NULL,
+ ngx_http_aws_auth_variable_s3, 0, NGX_HTTP_VAR_CHANGEABLE, 0 },
+
+ { ngx_string(AWS_DATE_VARIABLE), NULL,
+ ngx_http_aws_auth_variable_date, 0, NGX_HTTP_VAR_CHANGEABLE, 0 },
+
+ { ngx_null_string, NULL, NULL, 0, 0, 0 }
+};
+
static ngx_int_t
register_variable(ngx_conf_t *cf)
{
- static ngx_str_t x = ngx_string(AWS_S3_VARIABLE);
+ ngx_http_variable_t *var, *v;
- ngx_http_variable_t *var;
+ for (v = ngx_http_aws_auth_vars; v->name.len; v++) {
+ var = ngx_http_add_variable(cf, &v->name, v->flags);
+ if (var == NULL) {
+ return NGX_ERROR;
+ }
- var = ngx_http_add_variable(cf, &x, NGX_HTTP_VAR_CHANGEABLE);
- if (var == NULL) {
- return NGX_ERROR;
+ var->get_handler = v->get_handler;
+ var->data = v->data;
}
- var->get_handler = ngx_http_aws_auth_variable_s3;
- var->data = (uintptr_t)NULL;
-
- return NGX_OK;
+ return NGX_OK;
}
/*

0 comments on commit be0a164

Please sign in to comment.