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:
parent
acc01f1109
commit
66728cb93f
3 changed files with 25 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "win_get_url - Fix handling of restricted headers as per (https://github.com/ansible/ansible/issues/57880)"
|
|
@ -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) {
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue