summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2016-09-24 17:50:58 +0200
committerDominik Picheta <dominikpicheta@gmail.com>2016-09-24 17:50:58 +0200
commitfa9ec7a6b54ae1fc59674f530a0ee4a7532ca5e7 (patch)
treea0db9e1f17f40166eee0816299e877ce93a8479f /lib
parent547fb7f1e4a37ee759171834ad651d68561a7c5d (diff)
downloadNim-fa9ec7a6b54ae1fc59674f530a0ee4a7532ca5e7.tar.gz
Handle redirects in HttpClient's post procs & post test.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/httpclient.nim10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 27b3b46be..5eeb54f32 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -964,6 +964,8 @@ proc get*(client: HttpClient | AsyncHttpClient,
   ## This procedure will follow redirects up to a maximum number of redirects
   ## specified in ``client.maxRedirects``.
   result = await client.request(url, HttpGET)
+
+  # Handle redirects.
   var lastURL = url
   for i in 1..client.maxRedirects:
     if result.status.redirection():
@@ -990,3 +992,11 @@ proc post*(client: HttpClient | AsyncHttpClient, url: string, body = "",
   client.headers["Content-Length"] = $len(xb)
 
   result = await client.request(url, HttpPOST, xb)
+  # Handle redirects.
+  var lastURL = url
+  for i in 1..client.maxRedirects:
+    if result.status.redirection():
+      let redirectTo = getNewLocation(lastURL, result.headers)
+      var meth = if result.status != "307": HttpGet else: HttpPost
+      result = await client.request(redirectTo, meth, xb)
+      lastURL = redirectTo
5a6c688b58d4ccb91b6ad24a'>^
85e21158d ^
03ba0f3e2 ^
f3d530e48 ^
03ba0f3e2 ^
85e21158d ^
e7cdb1d69 ^
03ba0f3e2 ^



e7cdb1d69 ^
03ba0f3e2 ^
1284827df ^
03ba0f3e2 ^

8c0e27e8d ^

1284827df ^
39049e151 ^
03ba0f3e2 ^





39049e151 ^
e7cdb1d69 ^
39049e151 ^

03ba0f3e2 ^

e7cdb1d69 ^

7d6500f1d ^
1284827df ^
39049e151 ^
1284827df ^
03ba0f3e2 ^
39049e151 ^
e65c296bc ^
39049e151 ^
03ba0f3e2 ^


f485ebe16 ^
85e21158d ^
03ba0f3e2 ^
eea2a6360 ^
03ba0f3e2 ^

e4081a720 ^

03ba0f3e2 ^
e6c5622aa ^
a4e2b0c15 ^
03ba0f3e2 ^
1284827df ^
153441db1 ^
a42545ea3 ^
39049e151 ^
153441db1 ^
328e7a100 ^
153441db1 ^




03ba0f3e2 ^

3a13706d7 ^


e7cdb1d69 ^
03ba0f3e2 ^
92b8fac94 ^
7d6500f1d ^
328e7a100 ^
f485ebe16 ^
df1ec0939 ^
f485ebe16 ^









56b4e3ad9 ^

328e7a100 ^
56b4e3ad9 ^
73c6efdf6 ^
03ba0f3e2 ^
85e21158d ^
03ba0f3e2 ^
39049e151 ^
03ba0f3e2 ^
1284827df ^
153441db1 ^
74bf31661 ^




153441db1 ^
b5a96d28c ^
153441db1 ^




39049e151 ^
85e21158d ^
03ba0f3e2 ^

b234b082b ^
f7f3a25be ^
39049e151 ^
b234b082b ^
39049e151 ^
03ba0f3e2 ^
39049e151 ^


03ba0f3e2 ^
85e21158d ^

438703f59 ^
03ba0f3e2 ^
39049e151 ^
03ba0f3e2 ^
b234b082b ^
5c33f7651 ^
39049e151 ^
5c33f7651 ^
39049e151 ^







c6235920c ^

39049e151 ^
ab6f79340 ^

6ddd4e6a3 ^
4b0ba5e3f ^
39049e151 ^
1284827df ^
6ddd4e6a3 ^
fab69661a ^
39049e151 ^
ab6f79340 ^

b234b082b ^
6ddd4e6a3 ^
39049e151 ^





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