Revision 666432313633 () - Diff

Link to this snippet: https://friendpaste.com/3WC8RhvK2E9Rh2pE03wysn
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
This is my testing setup: I created a new database (test) that doesn't use any VHost rules.

Inside it I created a design document that only has rewrites field. There are three different rewrite configurations I used and 4 commands that I ran. For each command run I provide exact command I used, the output, my comment
of the output and relevant log from couch.log.

I always sent the same document contained in file "example" - namely:
{
"type": "comment"
}

Below are the test results:
----------------------------------------------------------------------------------------------------
## Test 1:
# rewrites config:
[
{
"to": "../..",
"from": ":db"
}
]

---------------------

# Executed command 1.1:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/
{"ok":true,"id":"ce8b504d63666c9257cc07537c00aa70","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: expected result - everything is fine.

---------------------

# Executed command 1.2:
$ curl -X PUT -d @example -H "Content-type:application/json" http://localhost:5984/test/_design/test/_rewrite/test/randomid324324
{"error":"not_found","reason":"missing"}

# Comment: result expected since there is no ID parameter passed through - due to the rewrite rule

#LOG:
[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] 'PUT' /test/_design/test/_rewrite/test/randomid324324 {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] OAuth Params: []

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Minor error in HTTP request: not_found

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Stacktrace: [{couch_httpd_rewrite,handle_rewrite_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 21:42:17 GMT] [info] [<0.8844.3>] 127.0.0.1 - - 'PUT' /test/_design/test/_rewrite/test/randomid324324 404

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] httpd 404 error response:
{"error":"not_found","reason":"missing"}

---------------------


# Executed command 1.3:
$curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/_design/test/_rewrite/test/
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

# Comment: Rewrite is wrong - also peculiar it won't take application/json content type.

# LOG:
[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST' /test/_design/test/_rewrite/test/ {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: []

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] rewrite to "/test/_design/..?db=test"


[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST' /test/_design/..?db=test {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: [{"db","test"}]

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Minor error in HTTP request: {bad_ctype,

"Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Stacktrace: [{couch_httpd,validate_ctype,2},
{couch_httpd_db,db_doc_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 21:51:55 GMT] [info] [<0.9453.3>] 127.0.0.1 - - 'POST' /test/_design/..?db=test 415

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] httpd 415 error response:
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

---------------------

# Executed command 1.4:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/randomid32420
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

# Comment: I did this one just because - and I noticed that when you post with and ID - it wont accept JSON content type

# LOG:
[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] 'POST' /test/randomid32420 {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] OAuth Params: []

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Minor error in HTTP request: {bad_ctype,

"Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Stacktrace: [{couch_httpd,validate_ctype,2},
{couch_httpd_db,db_doc_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 21:54:23 GMT] [info] [<0.9490.3>] 127.0.0.1 - - 'POST' /test/randomid32420 415

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] httpd 415 error response:
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}



----------------------------------------------------------------------------------------------------


## Test 2:

# Rewrites config:
[
{
"to": "../../*",
"from": ":db/*"
}
]

# Executed command 2.1:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/
{"ok":true,"id":"ce8b504d63666c9257cc07537c00af99","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK, everything is fine

---------------------

#Executed command 2.2:
$ curl -X PUT -d @example -H "Content-type:application/json" http://localhost:5984/test/_design/test/_rewrite/test/randomid3125
{"ok":true,"id":"randomid3125","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK, everything is fine - since now rewrite rule appropriately handles the ID.

---------------------

#Executed command 2.3:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/_design/test/_rewrite/test/
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

# Comment: Routing and content type are wrong (routing in PUT request - command 2.2 was done right!)

# LOG:
[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST' /test/_design/test/_rewrite/test/ {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] rewrite to "/test/_design/..?db=test"


[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST' /test/_design/..?db=test {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: [{"db","test"}]

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Minor error in HTTP request: {bad_ctype,

"Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Stacktrace: [{couch_httpd,validate_ctype,2},
{couch_httpd_db,db_doc_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:06:17 GMT] [info] [<0.10262.3>] 127.0.0.1 - - 'POST' /test/_design/..?db=test 415

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] httpd 415 error response:
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

---------------------

#Executed command 2.4:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/randomid32843
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

#Comment: No routing information in log, got Cotent type error.

#LOG:
[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] 'POST' /test/randomid32843 {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Minor error in HTTP request: {bad_ctype,

"Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Stacktrace: [{couch_httpd,validate_ctype,2},
{couch_httpd_db,db_doc_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:11:53 GMT] [info] [<0.10377.3>] 127.0.0.1 - - 'POST' /test/randomid32843 415

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] httpd 415 error response:
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

----------------------------------------------------------------------------------------------------


## Test 3:

# Rewrites config:
[
{
"to": "../../*",
"from": ":db/*"
},
{
"to": "../..",
"from": ":db"
}
]

---------------------

# Executed command 3.1:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/
{"ok":true,"id":"ce8b504d63666c9257cc07537c00bbe3","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK! works as expected

---------------------

#Executed command 3.2:
$ curl -X PUT -d @example -H "Content-type:application/json" http://localhost:5984/test/_design/test/_rewrite/test/randomid43242
{"ok":true,"id":"randomid43242","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK! works as expected

---------------------

#Executed command 3.3:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/_design/test/_rewrite/test/
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

# Comment: Rewrite issue and content type issue

# LOG:
[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST' /test/_design/test/_rewrite/test/ {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] rewrite to "/test/_design/..?db=test"


[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST' /test/_design/..?db=test {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: [{"db","test"}]

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Minor error in HTTP request: {bad_ctype,

"Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Stacktrace: [{couch_httpd,validate_ctype,2},
{couch_httpd_db,db_doc_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:19:55 GMT] [info] [<0.11199.3>] 127.0.0.1 - - 'POST' /test/_design/..?db=test 415

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] httpd 415 error response:
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

---------------------

#Executed command 3.4:
$ curl -d @example -H "Content-type:application/json" -e http://localhost:5984/test http://localhost:5984/test/randomid432432
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}

#Comment: Obviously no rewrite issue, however content type problem is there

#LOG:
[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] 'POST' /test/randomid432432 {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"23"},
{'Content-Type',"application/json"},
{'Host',"localhost:5984"},
{'Referer',"http://localhost:5984/test"},
{'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Minor error in HTTP request: {bad_ctype,

"Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Stacktrace: [{couch_httpd,validate_ctype,2},
{couch_httpd_db,db_doc_req,3},
{couch_httpd_db,do_db_req,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5},
{proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:21:24 GMT] [info] [<0.11220.3>] 127.0.0.1 - - 'POST' /test/randomid432432 415

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] httpd 415 error response:
{"error":"bad_content_type","reason":"Content-Type must be multipart/form-data"}