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
|
defmodule HttpTest do
use CouchTestCase
@moduletag :http
@tag :with_db
test "location header", context do
db_name = context[:db_name]
resp = Couch.put("/#{db_name}/test", body: %{})
db_url = Couch.process_url("/" <> db_name)
assert resp.headers.hdrs["location"] == db_url <> "/test"
end
@tag :with_db
test "location header should include X-Forwarded-Host", context do
db_name = context[:db_name]
resp =
Couch.put("/#{db_name}/test2",
body: %{},
headers: ["X-Forwarded-Host": "mysite.com"]
)
assert resp.headers.hdrs["location"] == "http://mysite.com/#{db_name}/test2"
end
@tag :with_db
test "location header should include custom header", context do
db_name = context[:db_name]
server_config = [
%{
:section => "httpd",
:key => "x_forwarded_host",
:value => "X-Host"
}
]
run_on_modified_server(server_config, fn ->
resp =
Couch.put("/#{db_name}/test3",
body: %{},
headers: ["X-Host": "mysite2.com"]
)
assert resp.headers.hdrs["location"] == "http://mysite2.com/#{db_name}/test3"
end)
end
@tag :with_db
test "COUCHDB-708: newlines document names", context do
db_name = context[:db_name]
resp =
Couch.put("/#{db_name}/docid%0A/attachment.txt",
body: %{},
headers: ["Content-Type": "text/plain;charset=utf-8"]
)
db_url = Couch.process_url("/" <> db_name)
assert resp.headers.hdrs["location"] == db_url <> "/docid%0A/attachment.txt"
resp =
Couch.put("/#{db_name}/docidtest%0A",
body: %{},
headers: ["Content-Type": "text/plain;charset=utf-8"]
)
db_url = Couch.process_url("/" <> db_name)
assert resp.headers.hdrs["location"] == db_url <> "/docidtest%0A"
resp =
Couch.post("/#{db_name}/",
body: %{_id: "docidtestpost%0A"},
headers: ["Content-Type": "application/json"]
)
db_url = Couch.process_url("/" <> db_name)
assert resp.headers.hdrs["location"] == db_url <> "/docidtestpost%250A"
end
end
|