* fix #7680 * Don't send on every HTTP method * These should be squashed * 80 column limit
This commit is contained in:
parent
ce1bd913cf
commit
397e173139
1 changed files with 6 additions and 3 deletions
|
|
@ -745,10 +745,11 @@ proc downloadFile*(url: string, outputFilename: string,
|
||||||
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||||
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
||||||
# GET
|
# GET
|
||||||
result = httpMethod.toUpperAscii()
|
let upperMethod = httpMethod.toUpperAscii()
|
||||||
|
result = upperMethod
|
||||||
result.add ' '
|
result.add ' '
|
||||||
|
|
||||||
if proxy.isNil or (not proxy.isNil and requestUrl.scheme == "https"):
|
if proxy.isNil or requestUrl.scheme == "https":
|
||||||
# /path?query
|
# /path?query
|
||||||
if requestUrl.path[0] != '/': result.add '/'
|
if requestUrl.path[0] != '/': result.add '/'
|
||||||
result.add(requestUrl.path)
|
result.add(requestUrl.path)
|
||||||
|
|
@ -774,7 +775,9 @@ proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||||
add(result, "Connection: Keep-Alive\c\L")
|
add(result, "Connection: Keep-Alive\c\L")
|
||||||
|
|
||||||
# Content length header.
|
# Content length header.
|
||||||
if body.len > 0 and not headers.hasKey("Content-Length"):
|
const requiresBody = ["POST", "PUT", "PATCH"]
|
||||||
|
let needsContentLength = body.len > 0 or upperMethod in requiresBody
|
||||||
|
if needsContentLength and not headers.hasKey("Content-Length"):
|
||||||
add(result, "Content-Length: " & $body.len & "\c\L")
|
add(result, "Content-Length: " & $body.len & "\c\L")
|
||||||
|
|
||||||
# Proxy auth header.
|
# Proxy auth header.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue