Skip to content
This repository
Browse code

A handler for OPTIONS method that facilitates HTML5 uploades

  • Loading branch information...
commit 8a9d65c678b739c333343a3c2bb7d582f7f5e3b1 1 parent 7990a22
authored December 14, 2010

Showing 1 changed file with 24 additions and 2 deletions. Show diff stats Hide diff stats

  1. 26  ngx_http_upload_module.c
26  ngx_http_upload_module.c
@@ -243,6 +243,7 @@ typedef struct ngx_http_upload_ctx_s {
243 243
 } ngx_http_upload_ctx_t;
244 244
 
245 245
 static ngx_int_t ngx_http_upload_handler(ngx_http_request_t *r);
  246
+static ngx_int_t ngx_http_upload_options_handler(ngx_http_request_t *r);
246 247
 static ngx_int_t ngx_http_upload_body_handler(ngx_http_request_t *r);
247 248
 
248 249
 static void *ngx_http_upload_create_loc_conf(ngx_conf_t *cf);
@@ -710,11 +711,14 @@ ngx_http_upload_handler(ngx_http_request_t *r)
710 711
     ngx_http_upload_ctx_t     *u;
711 712
     ngx_int_t                 rc;
712 713
 
  714
+    ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);
  715
+
  716
+    if((r->method & NGX_HTTP_OPTIONS) && ulcf->resumable_uploads)
  717
+        return ngx_http_upload_options_handler(r);
  718
+
713 719
     if (!(r->method & NGX_HTTP_POST))
714 720
         return NGX_HTTP_NOT_ALLOWED;
715 721
 
716  
-    ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);
717  
-
718 722
     u = ngx_http_get_module_ctx(r, ngx_http_upload_module);
719 723
 
720 724
     if (u == NULL) {
@@ -816,6 +820,24 @@ static ngx_int_t ngx_http_upload_add_headers(ngx_http_request_t *r, ngx_http_upl
816 820
     return NGX_OK;
817 821
 } /* }}} */
818 822
 
  823
+static ngx_int_t ngx_http_upload_options_handler(ngx_http_request_t *r) { /* {{{ */
  824
+    ngx_http_upload_loc_conf_t *ulcf;
  825
+
  826
+    ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);
  827
+
  828
+    r->headers_out.status = NGX_HTTP_OK;
  829
+
  830
+    if(ngx_http_upload_add_headers(r, ulcf) != NGX_OK) {
  831
+        return NGX_HTTP_INTERNAL_SERVER_ERROR;
  832
+    }
  833
+
  834
+    r->header_only = 1;
  835
+    r->headers_out.content_length_n = 0;
  836
+    r->allow_ranges = 0;
  837
+
  838
+    return ngx_http_send_header(r);
  839
+} /* }}} */
  840
+
819 841
 static ngx_int_t ngx_http_upload_body_handler(ngx_http_request_t *r) { /* {{{ */
820 842
     ngx_http_upload_loc_conf_t  *ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);
821 843
     ngx_http_upload_ctx_t       *ctx = ngx_http_get_module_ctx(r, ngx_http_upload_module);

0 notes on commit 8a9d65c

Please sign in to comment.
Something went wrong with that request. Please try again.