thqby / ahk2_lib

MIT License
197 stars 26 forks source link

Why aren't my headers being set? #45

Closed Qriist closed 5 months ago

Qriist commented 5 months ago

I'm using thqby's Winhttp class with my pull request. (My changes shouldn't have any impact on this problem.)

I am trying to set an Accept-Encoding header but it's being... difficult. Not throwing any errors, and not failing, just not returning the expected headers/data.

Code used:

#requires Autohotkey v2.0
#Include <Winhttp>

url := "https://titsandasses.org/"
web := Winhttp()

req := web.openRequest("GET",url,"UTF-8")
req.setRequestHeader("Accept-Encoding","gzip")
req.send()

msgbox req.getAllResponseHeaders()

ahk gives me:

HTTP/1.1 200 OK
Connection: Keep-Alive
Date: Sun, 11 Feb 2024 19:46:51 GMT
Keep-Alive: timeout=5, max=100
Content-Length: 196
Content-Type: text/html
Last-Modified: Mon, 25 Apr 2005 13:39:47 GMT
Accept-Ranges: bytes
ETag: "c4-3f592f0f8cec0"
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding

There is no Content-Encoding response header.

Meanwhile, using this command: curl -v -s -o nul -H "Accept-Encoding: gzip" --output - https://titsandasses.org/

curl gives me:


HTTP/1.1 200 OK
Date: Sun, 11 Feb 2024 19:38:31 GMT
Server: Apache/2.4.38 (Debian)
Last-Modified: Mon, 25 Apr 2005 13:39:47 GMT
ETag: "c4-3f592f0f8cec0-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 121
Content-Type: text/html

Note the presence of the Content-Encoding header and the smaller Content-Length value.

Any ideas?

thqby commented 5 months ago

Maybe curl sets some other request header.

In addition, WinHttp does not support gzip decoding, WinHttp.WinHttpRequest.5.1 supports.

Qriist commented 5 months ago

Maybe curl sets some other request header.

No, it's setting what I asked it to image

In addition, WinHttp does not support gzip decoding, WinHttp.WinHttpRequest.5.1 supports.

Ohhh then should I use the WinHttpRequest library that you've made, instead? https://github.com/thqby/ahk2_lib/blob/master/WinHttpRequest.ahk

thqby commented 5 months ago

In winhttp, setRequestHeader("Accept-Encoding","gzip") does not appear to take effect because gzip is not supported.

url := "https://titsandasses.org/"
web := ComObject('WinHttp.WinHttpRequest.5.1')

web.Open("GET",url)
web.SetRequestHeader("Accept","*/*")
web.SetRequestHeader("Accept-Encoding","gzip")
web.Send()

MsgBox web.getAllResponseHeaders()
Connection: Keep-Alive
Date: Mon, 12 Feb 2024 09:16:02 GMT
Keep-Alive: timeout=5, max=100
Content-Length: 121
Content-Type: text/html
Content-Encoding: gzip
Last-Modified: Mon, 25 Apr 2005 13:39:47 GMT
Accept-Ranges: bytes
ETag: "c4-3f592f0f8cec0-gzip"
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding