annotate src/http/modules/ngx_http_dav_module.c @ 210:14050d2bec9b NGINX_0_3_52

nginx 0.3.52 *) Change: the ngx_http_index_module behavior for the "POST /" requests is reverted to the 0.3.40 version state: the module now does not return the 405 error. *) Bugfix: the worker process may got caught in an endless loop if the limit rate was used; bug appeared in 0.3.37. *) Bugfix: ngx_http_charset_module logged "unknown charset" alert, even if the recoding was not needed; bug appeared in 0.3.50. *) Bugfix: if a code response of the PUT request was 409, then a temporary file was not removed.
author Igor Sysoev <http://sysoev.ru>
date Mon, 03 Jul 2006 00:00:00 +0400
parents af37b7cb6698
children 56688ed172c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 #define NGX_HTTP_DAV_OFF 2
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 typedef struct {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 ngx_uint_t methods;
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
16 ngx_flag_t create_full_put_path;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 } ngx_http_dav_loc_conf_t;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 static ngx_int_t ngx_http_dav_handler(ngx_http_request_t *r);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 static void ngx_http_dav_put_handler(ngx_http_request_t *r);
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
22 static ngx_int_t ngx_http_dav_error(ngx_http_request_t *, ngx_err_t err,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
23 ngx_int_t not_found, char *failed, u_char *path);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
24 static ngx_int_t ngx_http_dav_location(ngx_http_request_t *r, u_char *path);
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 void *parent, void *child);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 static ngx_int_t ngx_http_dav_init(ngx_cycle_t *cycle);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 static ngx_conf_bitmask_t ngx_http_dav_methods_mask[] = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 { ngx_string("off"), NGX_HTTP_DAV_OFF },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 { ngx_string("put"), NGX_HTTP_PUT },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 { ngx_string("delete"), NGX_HTTP_DELETE },
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
35 { ngx_string("mkcol"), NGX_HTTP_MKCOL },
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 { ngx_null_string, 0 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 static ngx_command_t ngx_http_dav_commands[] = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 { ngx_string("dav_methods"),
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 ngx_conf_set_bitmask_slot,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 NGX_HTTP_LOC_CONF_OFFSET,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 offsetof(ngx_http_dav_loc_conf_t, methods),
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 &ngx_http_dav_methods_mask },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
49 { ngx_string("create_full_put_path"),
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
50 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
51 ngx_conf_set_flag_slot,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
52 NGX_HTTP_LOC_CONF_OFFSET,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
53 offsetof(ngx_http_dav_loc_conf_t, create_full_put_path),
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
54 NULL },
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
55
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 ngx_null_command
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 ngx_http_module_t ngx_http_dav_module_ctx = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 NULL, /* preconfiguration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 NULL, /* postconfiguration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 NULL, /* create main configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 NULL, /* init main configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 NULL, /* create server configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 NULL, /* merge server configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 ngx_http_dav_create_loc_conf, /* create location configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 ngx_http_dav_merge_loc_conf /* merge location configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 ngx_module_t ngx_http_dav_module = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 NGX_MODULE_V1,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 &ngx_http_dav_module_ctx, /* module context */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 ngx_http_dav_commands, /* module directives */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 NGX_HTTP_MODULE, /* module type */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 NULL, /* init master */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 ngx_http_dav_init, /* init module */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 NULL, /* init process */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 NULL, /* init thread */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 NULL, /* exit thread */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 NULL, /* exit process */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 NULL, /* exit master */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 NGX_MODULE_V1_PADDING
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 static ngx_int_t
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 ngx_http_dav_handler(ngx_http_request_t *r)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 {
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
94 char *failed;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 ngx_int_t rc;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 ngx_str_t path;
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
97 ngx_file_info_t fi;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 ngx_http_dav_loc_conf_t *dlcf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 /* TODO: Win32 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 if (r->zero_in_uri) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107 if (!(r->method & dlcf->methods)) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 switch (r->method) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 case NGX_HTTP_PUT:
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 if (r->uri.data[r->uri.len - 1] == '/') {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 r->request_body_in_file_only = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 r->request_body_in_persistent_file = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 r->request_body_delete_incomplete_file = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 r->request_body_file_group_access = 1;
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
123 r->request_body_file_log_level = 0;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 rc = ngx_http_read_client_request_body(r, ngx_http_dav_put_handler);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 return rc;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 return NGX_DONE;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 case NGX_HTTP_DELETE:
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
135 if (r->headers_in.content_length_n > 0) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
136 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
137 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
138
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
139 rc = ngx_http_discard_body(r);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
140
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
141 if (rc != NGX_OK && rc != NGX_AGAIN) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
142 return rc;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 ngx_http_map_uri_to_path(r, &path, 0);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 "http delete filename: \"%s\"", path.data);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
150 if (ngx_file_info(path.data, &fi) != -1) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
151
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
152 if (ngx_is_dir(&fi)) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
153
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
154 if (r->uri.data[r->uri.len - 1] != '/'
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
155 || r->headers_in.depth == NULL
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
156 || r->headers_in.depth->value.len != sizeof("infinity") - 1
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
157 || ngx_strcmp(r->headers_in.depth->value.data, "infinity")
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
158 != 0)
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
159 {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
160 return NGX_HTTP_BAD_REQUEST;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
161 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
162
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
163 if (ngx_delete_dir(path.data) != NGX_FILE_ERROR) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
164 return NGX_HTTP_NO_CONTENT;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
165 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
166
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
167 failed = ngx_delete_dir_n;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
168
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
169 } else {
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
171 if (r->uri.data[r->uri.len - 1] == '/') {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
172 return NGX_HTTP_BAD_REQUEST;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
173 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
174
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
175 if (r->headers_in.depth
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
176 && r->headers_in.depth->value.len == 1
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
177 && r->headers_in.depth->value.data[0] == '1')
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
178 {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
179 return NGX_HTTP_BAD_REQUEST;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
180 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
181
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
182 if (ngx_delete_file(path.data) != NGX_FILE_ERROR) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
183 return NGX_HTTP_NO_CONTENT;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
184 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
185
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
186 failed = ngx_delete_file_n;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
187 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
188
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
189 } else {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
190 failed = ngx_file_info_n;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
193 return ngx_http_dav_error(r, ngx_errno, NGX_HTTP_NOT_FOUND, failed,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
194 path.data);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
195
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
196 case NGX_HTTP_MKCOL:
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
197
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
198 if (r->uri.data[r->uri.len - 1] != '/') {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
199 return NGX_DECLINED;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
200 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
201
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
202 if (r->headers_in.content_length_n > 0) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
203 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
204 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
205
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
206 rc = ngx_http_discard_body(r);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
207
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
208 if (rc != NGX_OK && rc != NGX_AGAIN) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
209 return rc;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
210 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
211
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
212 ngx_http_map_uri_to_path(r, &path, 0);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
213
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
214 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
215 "http mkcol path: \"%s\"", path.data);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
216
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
217 if (ngx_create_dir(path.data) != NGX_FILE_ERROR) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
218 if (ngx_http_dav_location(r, path.data) != NGX_OK) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
219 return NGX_HTTP_INTERNAL_SERVER_ERROR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
220 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
221
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
222 return NGX_HTTP_CREATED;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
223 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
224
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
225 return ngx_http_dav_error(r, ngx_errno, NGX_HTTP_CONFLICT,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
226 ngx_create_dir_n, path.data);
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 static void
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 ngx_http_dav_put_handler(ngx_http_request_t *r)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 {
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
236 ngx_err_t err;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
237 ngx_str_t *temp, path;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
238 ngx_uint_t status;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
239 ngx_file_info_t fi;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
240 ngx_http_dav_loc_conf_t *dlcf;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
242 ngx_http_map_uri_to_path(r, &path, 0);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 "http put filename: \"%s\"", path.data);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247 temp = &r->request_body->temp_file->file.name;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 if (ngx_file_info(path.data, &fi) == -1) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 status = NGX_HTTP_CREATED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 } else {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 status = NGX_HTTP_NO_CONTENT;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
256 if (ngx_is_dir(&fi)) {
210
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
257 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
258 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
259 ngx_delete_file_n " \"%s\" failed",
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
260 temp->data);
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
261 }
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
262
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
263 ngx_http_finalize_request(r, NGX_HTTP_CONFLICT);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
264 return;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
265 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
266
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 goto ok;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 err = ngx_errno;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
273 if (err == NGX_ENOENT) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
274
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
275 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
276
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
277 if (dlcf->create_full_put_path) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
278 err = ngx_create_full_path(path.data);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
279
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
280 if (err == 0) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
281 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
282 goto ok;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
283 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
284
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
285 err = ngx_errno;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
286 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
287 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
288 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
289
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 #if (NGX_WIN32)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292 if (err == NGX_EEXIST) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 if (ngx_win32_rename_file(temp, &path, r->pool) != NGX_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 goto ok;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300 err = ngx_errno;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
301 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 #endif
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304
210
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
305 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
306 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
307 ngx_delete_file_n " \"%s\" failed",
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
308 temp->data);
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
309 }
14050d2bec9b nginx 0.3.52
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
310
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
311 ngx_http_finalize_request(r, ngx_http_dav_error(r, err, NGX_HTTP_CONFLICT,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
312 ngx_rename_file_n,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
313 path.data));
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316 ok:
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
318 if (status == NGX_HTTP_CREATED) {
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
319 if (ngx_http_dav_location(r, path.data) != NGX_OK) {
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 }
188
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 186
diff changeset
323
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 186
diff changeset
324 r->headers_out.content_length_n = 0;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 r->headers_out.status = status;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328 r->header_only = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330 ngx_http_finalize_request(r, ngx_http_send_header(r));
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
335 static ngx_int_t
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
336 ngx_http_dav_error(ngx_http_request_t *r, ngx_err_t err, ngx_int_t not_found,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
337 char *failed, u_char *path)
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
338 {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
339 ngx_int_t rc;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
340 ngx_uint_t level;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
341
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
342 if (err == NGX_ENOENT || err == NGX_ENOTDIR || err == NGX_ENAMETOOLONG) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
343 level = NGX_LOG_ERR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
344 rc = not_found;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
345
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
346 } else if (err == NGX_EACCES || err == NGX_EPERM) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
347 level = NGX_LOG_ERR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
348 rc = NGX_HTTP_FORBIDDEN;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
349
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
350 } else if (err == NGX_EEXIST) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
351 level = NGX_LOG_ERR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
352 rc = NGX_HTTP_NOT_ALLOWED;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
353
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
354 } else if (err == NGX_ENOSPC) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
355 level = NGX_LOG_CRIT;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
356 rc = NGX_HTTP_INSUFFICIENT_STORAGE;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
357
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
358 } else {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
359 level = NGX_LOG_CRIT;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
360 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
361 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
362
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
363 ngx_log_error(level, r->connection->log, err,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
364 "%s \"%s\" failed", failed, path);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
365
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
366 return rc;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
367 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
368
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
369
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
370 static ngx_int_t
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
371 ngx_http_dav_location(ngx_http_request_t *r, u_char *path)
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
372 {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
373 u_char *location;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
374 ngx_http_core_loc_conf_t *clcf;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
375
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
376 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
377 if (r->headers_out.location == NULL) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
378 return NGX_ERROR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
379 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
380
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
381 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
382
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
383 if (!clcf->alias && clcf->root_lengths == NULL) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
384 location = path + clcf->root.len;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
385
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
386 } else {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
387 location = ngx_palloc(r->pool, r->uri.len);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
388 if (location == NULL) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
389 return NGX_ERROR;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
390 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
391
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
392 ngx_memcpy(location, r->uri.data, r->uri.len);
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
393 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
394
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
395 /*
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
396 * we do not need to set the r->headers_out.location->hash and
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
397 * r->headers_out.location->key fields
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
398 */
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
399
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
400 r->headers_out.location->value.len = r->uri.len;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
401 r->headers_out.location->value.data = location;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
402
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
403 return NGX_OK;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
404 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
405
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
406
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407 static void *
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 ngx_http_dav_create_loc_conf(ngx_conf_t *cf)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410 ngx_http_dav_loc_conf_t *conf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
411
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_dav_loc_conf_t));
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413 if (conf == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414 return NGX_CONF_ERROR;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
416
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417 /*
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418 * set by ngx_pcalloc():
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419 *
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420 * conf->methods = 0;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
423 conf->create_full_put_path = NGX_CONF_UNSET;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
424
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425 return conf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
427
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429 static char *
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430 ngx_http_dav_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
431 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432 ngx_http_dav_loc_conf_t *prev = parent;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433 ngx_http_dav_loc_conf_t *conf = child;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435 ngx_conf_merge_bitmask_value(conf->methods, prev->methods,
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
436 (NGX_CONF_BITMASK_SET|NGX_HTTP_DAV_OFF));
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
437
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
438 ngx_conf_merge_value(conf->create_full_put_path, prev->create_full_put_path,
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
439 0);
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
440
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 return NGX_CONF_OK;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
444
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
445 static ngx_int_t
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
446 ngx_http_dav_init(ngx_cycle_t *cycle)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
447 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448 ngx_http_handler_pt *h;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 ngx_http_core_main_conf_t *cmcf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
451 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
452
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
453 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454 if (h == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
455 return NGX_ERROR;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
456 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
457
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
458 *h = ngx_http_dav_handler;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
459
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
460 return NGX_OK;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461 }