win_get_url - Fix handling of restricted headers (#57892)

* fix 57880

* ADded test

* Remove host header from test

* TEst error

* Fix tests

* fix user agent test
This commit is contained in:
ShachafGoldstein 2019-06-17 22:25:38 +03:00 committed by Jordan Borean
parent acc01f1109
commit 66728cb93f
3 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "win_get_url - Fix handling of restricted headers as per (https://github.com/ansible/ansible/issues/57880)"

View file

@ -81,7 +81,25 @@ Function Invoke-AnsibleWebRequest {
$web_request.Method = $Method.($web_request.GetType().Name)
foreach ($header in $headers.GetEnumerator()) {
$web_request.Headers.Add($header.Key, $header.Value)
# some headers need to be set on the property itself
switch ($header.Key) {
Accept { $web_request.Accept = $header.Value }
Connection { $web_request.Connection = $header.Value }
Content-Length { $web_request.ContentLength = $header.Value }
Content-Type { $web_request.ContentType = $header.Value }
Expect { $web_request.Expect = $header.Value }
Date { $web_request.Date = $header.Value }
Host { $web_request.Host = $header.Value }
If-Modified-Since { $web_request.IfModifiedSince = $header.Value }
Range { $web_request.AddRange($header.Value) }
Referer { $web_request.Referer = $header.Value }
Transfer-Encoding {
$web_request.SendChunked = $true
$web_request.TransferEncoding = $header.Value
}
User-Agent { $web_request.UserAgent = $header.Value }
default { $web_request.Headers.Add($header.Key, $header.Value) }
}
}
if ($timeout) {

View file

@ -188,6 +188,8 @@
dest: '{{ testing_dir }}\headers.txt'
headers:
testing: 123
User-Agent: 'badAgent'
accept: 'text/html'
register: headers
- name: get result of send request with headers
@ -201,3 +203,5 @@
- headers is changed
- headers.status_code == 200
- (headers_actual.content | b64decode | from_json).headers.Testing == '123'
- (headers_actual.content | b64decode | from_json).headers["User-Agent"] == 'badAgent'
- (headers_actual.content | b64decode | from_json).headers.Accept == 'text/html'