winhttp
is a library used to interact with the Windows winhttp API.
It is designed take in a http.Request and return a http.Response from the go http
standard library.
This library returns a custom Client
that mimics the http.Client so that it can be a drop in replacement for the http.Client
.
This package's custom client also takes an http.Transport structure in the Transport
field to configure how the winhttp client is used.
This package uses the log/slog package for logging.
To retrieve the log output, create a new logger and call the slog.SetDefault() function.
All logging calls in this package are only for the DEBUG
logging level which are not output by default.
There is an example implementation in the example directory. Run the example code with:
PS C:\> go run .\examples\main.go
{"time":"2024-02-04T10:00:19.6010954-08:00","level":"INFO","msg":"building the HTTP request"}
{"time":"2024-02-04T10:00:19.60164-08:00","level":"INFO","msg":"building the HTTP client"}
{"time":"2024-02-04T10:00:19.60164-08:00","level":"INFO","msg":"sending the HTTP request","method":"GET","url":"https://httpbin.org/get"}
{"time":"2024-02-04T10:00:19.7671138-08:00","level":"INFO","msg":"recieved HTTP response","response":{"Status":"200 OK","StatusCode":200,"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Access-Control-Allow-Credentials":["true"],"Access-Control-Allow-Origin":["*"],"Connection":["keep-alive"],"Content-Length":["364"],"Content-Type":["application/json"],"Date":["Sun, 04 Feb 2024 18:00:19 GMT"],"Server":["gunicorn/19.9.0"]},"Body":{"Reader":{}},"ContentLength":364,"TransferEncoding":null,"Close":false,"Uncompressed":false,"Trailer":null,"Request":null,"TLS":null}}
{"time":"2024-02-04T10:00:19.7683439-08:00","level":"INFO","msg":"received HTTP payload data","data length":364}
{"time":"2024-02-04T10:00:19.7683439-08:00","level":"INFO","msg":"program finished running succesfully"}
The program's command line flags are:
-data string
data to send with the request
-debug
enable debug output
-method string
the HTTP METHOD for the request (default "GET")
-trace
enable SourceKey for debug output
-url string
the full URL for the request (default "https://httpbin.org/get")