winhttp

package module
v0.0.0-...-afae24f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2017 License: MPL-2.0 Imports: 3 Imported by: 0

README

GoWinHttp

GoWinHttp provides a Goish interface to the WinHTTP API. This aims to expose an API that matches or is quite close to the original API, while cleaning up the interface where possible to help it fit in with Go. Currently as much of WinHTTP as required for SpiderOak Semaphor is implemented, but we aim for eventual completeness. Because Win32 (and thus WinHTTP) has a reasonably consistent pattern of use that happens to not be what's considered to be idiomatic Go, there will still be some rough edges. However, this package should enable someone with a basic understanding of WinHTTP and knowledge of Go to produce software using winhttp.dll.

It should be obvious but to be clear: this will build and run only on Windows.

We make very heavy use of the expanded Windows sys package.

Installing:

go get github.com/SpiderOak/GoWinHttp

Use:

Basics

The assumption we are making is that you can look up function calls in MSDN and you have some knowledge of Go. To help mesh understanding, we use argument and field names from MSDN, stripping off Hungarian notation when it doesn't reduce clarity. We also try to expose Go types to the caller and convert to Win32-friendly types internally. Finally, arguments and struct fields that are noted as reserved in MSDN we try to hide here- reserved arguments aren't in functions, and while we need to keep reserved struct fields to retain memory layouts, we don't export them.

NOTE: We currently do not support async WinHTTP operation. This will be rectified soon.

Types

As above, we try to hold hard to using unspecial Go types for function arguments, and these types will either map to their Win32 versions or we will do a little magic to make it work (such as working with []byte instead of forcing you to deal with *byte for data). There three exceptions to this:

  1. We define an HInternet type so the compiler can help ensure you're only passing around internet handles from us.
  2. We have a variety of struct types not available from the system.
  3. Generic interfaces in WinHTTP requiring use of pointers. See "Pointers", below.
Pointers

The Win32 API operates in an OO-ish manner via a C API. This means we will be sometimes passing data via pointer, and sometimes we aren't going to be able to hide this from you. The unsafe.Pointer documentation notes special use cases for making syscalls. Functions where we cannot avoid using C-compatible pointers via the uintptr(unsafe.Pointer(&x)) pattern are specifically marked with compiler pragmas to operate safely with that pattern. Write to your local congressperson or MP about generics in Go if this is upsetting.

Example:

Get a session handle:

hsession, err := winhttp.Open(
    "winhttp",
    winhttp.WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
    "",
    "",
    0,
)
if err != nil {
    return "", err
}

Set options on a request (also an example of passing in pointers):

dwFlags := uint32(winhttp.SECURITY_FLAG_IGNORE_UNKNOWN_CA)

err = winhttp.SetOption(
    request,
    winhttp.WINHTTP_OPTION_SECURITY_FLAGS,
    uintptr(unsafe.Pointer(&dwFlags)),
    unsafe.Sizeof(dwFlags),
)
if err != nil {
    fmt.Printf("error in WinHttpSetOption: %s", err)
}

Contact

Feel free to reachout to matt at spideroak dot com for questions or concerns about this library!

Legalese

This work is covered by the Mozilla Public License, v2. See LICENSE.md for more information.

© 2017 SpiderOak, Inc.

Documentation

Rendered for windows/amd64

Overview

Package winhttp provides a Golang-ish interface to the WinHTTP API. Because WinHTTP has a somewhat consistent pattern of use that contrasts with what ideomatic Golang expects, there will still be some rough edges (see GetOption and SetOption for examples), but this package should enable someone with basic understanding of WinHTTP and knowledge of Go to be able to use it to produce software making use of winhttp.dll.

Some notes:

  • Error handling may look a little weird. As per https://godoc.org/golang.org/x/sys/windows#LazyProc.Call , we *must* check the primary return value to see if the error is valid. To be more Golang-y, we do that here and return nil for errors when we don't have an error condition.
  • We currently do not support WinHTTP in async operation.
  • To avoid constantly looking up procs, we cache them here in private globals.
  • To help mesh one's understanding of what's going on here against MSDN documentation, we're using field and argument names from MSDN.
  • Arguments and struct fields marked as reserved in MSDN are either not present in function arguments here or not exported in struct types. We have to include them in structs to preserve memory layouts that Windows will expect.

Index

Constants

View Source
const (
	/* WinHTTP error codes */
	WINHTTP_ERROR_BASE                                  = 12000
	ERROR_WINHTTP_OUT_OF_HANDLES                        = syscall.Errno(WINHTTP_ERROR_BASE + 1)
	ERROR_WINHTTP_TIMEOUT                               = syscall.Errno(WINHTTP_ERROR_BASE + 2)
	ERROR_WINHTTP_INTERNAL_ERROR                        = syscall.Errno(WINHTTP_ERROR_BASE + 4)
	ERROR_WINHTTP_INVALID_URL                           = syscall.Errno(WINHTTP_ERROR_BASE + 5)
	ERROR_WINHTTP_UNRECOGNIZED_SCHEME                   = syscall.Errno(WINHTTP_ERROR_BASE + 6)
	ERROR_WINHTTP_NAME_NOT_RESOLVED                     = syscall.Errno(WINHTTP_ERROR_BASE + 7)
	ERROR_WINHTTP_INVALID_OPTION                        = syscall.Errno(WINHTTP_ERROR_BASE + 9)
	ERROR_WINHTTP_OPTION_NOT_SETTABLE                   = syscall.Errno(WINHTTP_ERROR_BASE + 11)
	ERROR_WINHTTP_SHUTDOWN                              = syscall.Errno(WINHTTP_ERROR_BASE + 12)
	ERROR_WINHTTP_LOGIN_FAILURE                         = syscall.Errno(WINHTTP_ERROR_BASE + 15)
	ERROR_WINHTTP_OPERATION_CANCELLED                   = syscall.Errno(WINHTTP_ERROR_BASE + 17)
	ERROR_WINHTTP_INCORRECT_HANDLE_TYPE                 = syscall.Errno(WINHTTP_ERROR_BASE + 18)
	ERROR_WINHTTP_INCORRECT_HANDLE_STATE                = syscall.Errno(WINHTTP_ERROR_BASE + 19)
	ERROR_WINHTTP_CANNOT_CONNECT                        = syscall.Errno(WINHTTP_ERROR_BASE + 29)
	ERROR_WINHTTP_CONNECTION_ERROR                      = syscall.Errno(WINHTTP_ERROR_BASE + 30)
	ERROR_WINHTTP_RESEND_REQUEST                        = syscall.Errno(WINHTTP_ERROR_BASE + 32)
	ERROR_WINHTTP_SECURE_CERT_DATE_INVALID              = syscall.Errno(WINHTTP_ERROR_BASE + 37)
	ERROR_WINHTTP_SECURE_CERT_CN_INVALID                = syscall.Errno(WINHTTP_ERROR_BASE + 38)
	ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED               = syscall.Errno(WINHTTP_ERROR_BASE + 44)
	ERROR_WINHTTP_SECURE_INVALID_CA                     = syscall.Errno(WINHTTP_ERROR_BASE + 45)
	ERROR_WINHTTP_SECURE_CERT_REV_FAILED                = syscall.Errno(WINHTTP_ERROR_BASE + 57)
	ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN               = syscall.Errno(WINHTTP_ERROR_BASE + 100)
	ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND               = syscall.Errno(WINHTTP_ERROR_BASE + 101)
	ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND                = syscall.Errno(WINHTTP_ERROR_BASE + 102)
	ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN                = syscall.Errno(WINHTTP_ERROR_BASE + 103)
	ERROR_WINHTTP_HEADER_NOT_FOUND                      = syscall.Errno(WINHTTP_ERROR_BASE + 150)
	ERROR_WINHTTP_INVALID_SERVER_RESPONSE               = syscall.Errno(WINHTTP_ERROR_BASE + 152)
	ERROR_WINHTTP_INVALID_HEADER                        = syscall.Errno(WINHTTP_ERROR_BASE + 153)
	ERROR_WINHTTP_INVALID_QUERY_REQUEST                 = syscall.Errno(WINHTTP_ERROR_BASE + 154)
	ERROR_WINHTTP_HEADER_ALREADY_EXISTS                 = syscall.Errno(WINHTTP_ERROR_BASE + 155)
	ERROR_WINHTTP_REDIRECT_FAILED                       = syscall.Errno(WINHTTP_ERROR_BASE + 156)
	ERROR_WINHTTP_SECURE_CHANNEL_ERROR                  = syscall.Errno(WINHTTP_ERROR_BASE + 157)
	ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT                 = syscall.Errno(WINHTTP_ERROR_BASE + 166)
	ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT             = syscall.Errno(WINHTTP_ERROR_BASE + 167)
	ERROR_WINHTTP_SECURE_INVALID_CERT                   = syscall.Errno(WINHTTP_ERROR_BASE + 169)
	ERROR_WINHTTP_SECURE_CERT_REVOKED                   = syscall.Errno(WINHTTP_ERROR_BASE + 170)
	ERROR_WINHTTP_NOT_INITIALIZED                       = syscall.Errno(WINHTTP_ERROR_BASE + 172)
	ERROR_WINHTTP_SECURE_FAILURE                        = syscall.Errno(WINHTTP_ERROR_BASE + 175)
	ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR              = syscall.Errno(WINHTTP_ERROR_BASE + 178)
	ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE               = syscall.Errno(WINHTTP_ERROR_BASE + 179)
	ERROR_WINHTTP_AUTODETECTION_FAILED                  = syscall.Errno(WINHTTP_ERROR_BASE + 180)
	ERROR_WINHTTP_HEADER_COUNT_EXCEEDED                 = syscall.Errno(WINHTTP_ERROR_BASE + 181)
	ERROR_WINHTTP_HEADER_SIZE_OVERFLOW                  = syscall.Errno(WINHTTP_ERROR_BASE + 182)
	ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW = syscall.Errno(WINHTTP_ERROR_BASE + 183)
	ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW               = syscall.Errno(WINHTTP_ERROR_BASE + 184)
	ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY            = syscall.Errno(WINHTTP_ERROR_BASE + 185)
	ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY     = syscall.Errno(WINHTTP_ERROR_BASE + 186)
	WINHTTP_ERROR_LAST                                  = (WINHTTP_ERROR_BASE + 186)
)
View Source
const (
	SECURITY_FLAG_IGNORE_UNKNOWN_CA        = 0x00000100
	SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000
	SECURITY_FLAG_IGNORE_CERT_CN_INVALID   = 0x00001000
	SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE  = 0x00000200
	SECURITY_FLAG_SECURE                   = 0x00000001
	SECURITY_FLAG_STRENGTH_WEAK            = 0x10000000
	SECURITY_FLAG_STRENGTH_MEDIUM          = 0x40000000
	SECURITY_FLAG_STRENGTH_STRONG          = 0x20000000
)
View Source
const (
	INTERNET_DEFAULT_PORT       = 0
	INTERNET_DEFAULT_HTTP_PORT  = 80
	INTERNET_DEFAULT_HTTPS_PORT = 443

	WINHTTP_FLAG_ASYNC = 0x10000000

	WINHTTP_FLAG_SECURE               = 0x00800000
	WINHTTP_FLAG_ESCAPE_PERCENT       = 0x00000004
	WINHTTP_FLAG_NULL_CODEPAGE        = 0x00000008
	WINHTTP_FLAG_BYPASS_PROXY_CACHE   = 0x00000100
	WINHTTP_FLAG_REFRESH              = 0x00000100
	WINHTTP_FLAG_ESCAPE_DISABLE       = 0x00000040
	WINHTTP_FLAG_ESCAPE_DISABLE_QUERY = 0x00000080

	WINHTTP_AUTOPROXY_AUTO_DETECT         = 0x00000001
	WINHTTP_AUTOPROXY_CONFIG_URL          = 0x00000002
	WINHTTP_AUTOPROXY_HOST_KEEPCASE       = 0x00000004
	WINHTTP_AUTOPROXY_HOST_LOWERCASE      = 0x00000008
	WINHTTP_AUTOPROXY_RUN_INPROCESS       = 0x00010000
	WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY = 0x00020000
	WINHTTP_AUTOPROXY_NO_DIRECTACCESS     = 0x00040000
	WINHTTP_AUTOPROXY_NO_CACHE_CLIENT     = 0x00080000
	WINHTTP_AUTOPROXY_NO_CACHE_SVC        = 0x00100000

	WINHTTP_AUTOPROXY_SORT_RESULTS = 0x00400000

	WINHTTP_AUTO_DETECT_TYPE_DHCP  = 0x00000001
	WINHTTP_AUTO_DETECT_TYPE_DNS_A = 0x00000002

	WINHTTP_ACCESS_TYPE_DEFAULT_PROXY   = 0
	WINHTTP_ACCESS_TYPE_NO_PROXY        = 1
	WINHTTP_ACCESS_TYPE_NAMED_PROXY     = 3
	WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY = 4

	WINHTTP_NO_PROXY_NAME   = 0
	WINHTTP_NO_PROXY_BYPASS = 0

	WINHTTP_NO_ADDITIONAL_HEADERS = 0
	WINHTTP_NO_REQUEST_DATA       = 0

	WINHTTP_QUERY_MIME_VERSION              = 0
	WINHTTP_QUERY_CONTENT_TYPE              = 1
	WINHTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2
	WINHTTP_QUERY_CONTENT_ID                = 3
	WINHTTP_QUERY_CONTENT_DESCRIPTION       = 4
	WINHTTP_QUERY_CONTENT_LENGTH            = 5
	WINHTTP_QUERY_CONTENT_LANGUAGE          = 6
	WINHTTP_QUERY_ALLOW                     = 7
	WINHTTP_QUERY_PUBLIC                    = 8
	WINHTTP_QUERY_DATE                      = 9
	WINHTTP_QUERY_EXPIRES                   = 10
	WINHTTP_QUERY_LAST_MODIFIED             = 11
	WINHTTP_QUERY_MESSAGE_ID                = 12
	WINHTTP_QUERY_URI                       = 13
	WINHTTP_QUERY_DERIVED_FROM              = 14
	WINHTTP_QUERY_COST                      = 15
	WINHTTP_QUERY_LINK                      = 16
	WINHTTP_QUERY_PRAGMA                    = 17
	WINHTTP_QUERY_VERSION                   = 18 // special: part of status line
	WINHTTP_QUERY_STATUS_CODE               = 19 // special: part of status line
	WINHTTP_QUERY_STATUS_TEXT               = 20 // special: part of status line
	WINHTTP_QUERY_RAW_HEADERS               = 21 // special: all headers as ASCIIZ
	WINHTTP_QUERY_RAW_HEADERS_CRLF          = 22 // special: all headers
	WINHTTP_QUERY_CONNECTION                = 23
	WINHTTP_QUERY_ACCEPT                    = 24
	WINHTTP_QUERY_ACCEPT_CHARSET            = 25
	WINHTTP_QUERY_ACCEPT_ENCODING           = 26
	WINHTTP_QUERY_ACCEPT_LANGUAGE           = 27
	WINHTTP_QUERY_AUTHORIZATION             = 28
	WINHTTP_QUERY_CONTENT_ENCODING          = 29
	WINHTTP_QUERY_FORWARDED                 = 30
	WINHTTP_QUERY_FROM                      = 31
	WINHTTP_QUERY_IF_MODIFIED_SINCE         = 32
	WINHTTP_QUERY_LOCATION                  = 33
	WINHTTP_QUERY_ORIG_URI                  = 34
	WINHTTP_QUERY_REFERER                   = 35
	WINHTTP_QUERY_RETRY_AFTER               = 36
	WINHTTP_QUERY_SERVER                    = 37
	WINHTTP_QUERY_TITLE                     = 38
	WINHTTP_QUERY_USER_AGENT                = 39
	WINHTTP_QUERY_WWW_AUTHENTICATE          = 40
	WINHTTP_QUERY_PROXY_AUTHENTICATE        = 41
	WINHTTP_QUERY_ACCEPT_RANGES             = 42
	WINHTTP_QUERY_SET_COOKIE                = 43
	WINHTTP_QUERY_COOKIE                    = 44
	WINHTTP_QUERY_REQUEST_METHOD            = 45 // special: GET/POST etc.
	WINHTTP_QUERY_REFRESH                   = 46
	WINHTTP_QUERY_CONTENT_DISPOSITION       = 47

	WINHTTP_QUERY_AGE                   = 48
	WINHTTP_QUERY_CACHE_CONTROL         = 49
	WINHTTP_QUERY_CONTENT_BASE          = 50
	WINHTTP_QUERY_CONTENT_LOCATION      = 51
	WINHTTP_QUERY_CONTENT_MD5           = 52
	WINHTTP_QUERY_CONTENT_RANGE         = 53
	WINHTTP_QUERY_ETAG                  = 54
	WINHTTP_QUERY_HOST                  = 55
	WINHTTP_QUERY_IF_MATCH              = 56
	WINHTTP_QUERY_IF_NONE_MATCH         = 57
	WINHTTP_QUERY_IF_RANGE              = 58
	WINHTTP_QUERY_IF_UNMODIFIED_SINCE   = 59
	WINHTTP_QUERY_MAX_FORWARDS          = 60
	WINHTTP_QUERY_PROXY_AUTHORIZATION   = 61
	WINHTTP_QUERY_RANGE                 = 62
	WINHTTP_QUERY_TRANSFER_ENCODING     = 63
	WINHTTP_QUERY_UPGRADE               = 64
	WINHTTP_QUERY_VARY                  = 65
	WINHTTP_QUERY_VIA                   = 66
	WINHTTP_QUERY_WARNING               = 67
	WINHTTP_QUERY_EXPECT                = 68
	WINHTTP_QUERY_PROXY_CONNECTION      = 69
	WINHTTP_QUERY_UNLESS_MODIFIED_SINCE = 70

	WINHTTP_HEADER_NAME_BY_INDEX = ""
	WINHTTP_NO_OUTPUT_BUFFER     = 0
	WINHTTP_NO_HEADER_INDEX      = 0

	WINHTTP_OPTION_CALLBACK                      = 1
	WINHTTP_OPTION_RESOLVE_TIMEOUT               = 2
	WINHTTP_OPTION_CONNECT_TIMEOUT               = 3
	WINHTTP_OPTION_CONNECT_RETRIES               = 4
	WINHTTP_OPTION_SEND_TIMEOUT                  = 5
	WINHTTP_OPTION_RECEIVE_TIMEOUT               = 6
	WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT      = 7
	WINHTTP_OPTION_HANDLE_TYPE                   = 9
	WINHTTP_OPTION_READ_BUFFER_SIZE              = 12
	WINHTTP_OPTION_WRITE_BUFFER_SIZE             = 13
	WINHTTP_OPTION_PARENT_HANDLE                 = 21
	WINHTTP_OPTION_EXTENDED_ERROR                = 24
	WINHTTP_OPTION_SECURITY_FLAGS                = 31
	WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT   = 32
	WINHTTP_OPTION_URL                           = 34
	WINHTTP_OPTION_SECURITY_KEY_BITNESS          = 36
	WINHTTP_OPTION_PROXY                         = 38
	WINHTTP_OPTION_USER_AGENT                    = 41
	WINHTTP_OPTION_CONTEXT_VALUE                 = 45
	WINHTTP_OPTION_CLIENT_CERT_CONTEXT           = 47
	WINHTTP_OPTION_REQUEST_PRIORITY              = 58
	WINHTTP_OPTION_HTTP_VERSION                  = 59
	WINHTTP_OPTION_DISABLE_FEATURE               = 63
	WINHTTP_OPTION_CODEPAGE                      = 68
	WINHTTP_OPTION_MAX_CONNS_PER_SERVER          = 73
	WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER      = 74
	WINHTTP_OPTION_AUTOLOGON_POLICY              = 77
	WINHTTP_OPTION_SERVER_CERT_CONTEXT           = 78
	WINHTTP_OPTION_ENABLE_FEATURE                = 79
	WINHTTP_OPTION_WORKER_THREAD_COUNT           = 80
	WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT      = 81
	WINHTTP_OPTION_PASSPORT_COBRANDING_URL       = 82
	WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH       = 83
	WINHTTP_OPTION_SECURE_PROTOCOLS              = 84
	WINHTTP_OPTION_ENABLETRACING                 = 85
	WINHTTP_OPTION_PASSPORT_SIGN_OUT             = 86
	WINHTTP_OPTION_PASSPORT_RETURN_URL           = 87
	WINHTTP_OPTION_REDIRECT_POLICY               = 88
	WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS  = 89
	WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE      = 90
	WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE      = 91
	WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE       = 92
	WINHTTP_OPTION_CONNECTION_INFO               = 93
	WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST       = 94
	WINHTTP_OPTION_SPN                           = 96
	WINHTTP_OPTION_GLOBAL_PROXY_CREDS            = 97
	WINHTTP_OPTION_GLOBAL_SERVER_CREDS           = 98
	WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT           = 99
	WINHTTP_OPTION_REJECT_USERPWD_IN_URL         = 100
	WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS = 101
	WINHTTP_LAST_OPTION                          = WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS
	WINHTTP_OPTION_USERNAME                      = 0x1000
	WINHTTP_OPTION_PASSWORD                      = 0x1001
	WINHTTP_OPTION_PROXY_USERNAME                = 0x1002
	WINHTTP_OPTION_PROXY_PASSWORD                = 0x1003
	WINHTTP_ADDREQ_INDEX_MASK                    = 0x0000FFFF
	WINHTTP_ADDREQ_FLAGS_MASK                    = 0xFFFF0000
	WINHTTP_ADDREQ_FLAG_ADD_IF_NEW               = 0x10000000
	WINHTTP_ADDREQ_FLAG_ADD                      = 0x20000000
	WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA      = 0x40000000
	WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON  = 0x01000000
	WINHTTP_ADDREQ_FLAG_COALESCE                 = WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
	WINHTTP_ADDREQ_FLAG_REPLACE                  = 0x80000000

	WINHTTP_CALLBACK_STATUS_RESOLVING_NAME        = 0x00000001
	WINHTTP_CALLBACK_STATUS_NAME_RESOLVED         = 0x00000002
	WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER  = 0x00000004
	WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER   = 0x00000008
	WINHTTP_CALLBACK_STATUS_SENDING_REQUEST       = 0x00000010
	WINHTTP_CALLBACK_STATUS_REQUEST_SENT          = 0x00000020
	WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE    = 0x00000040
	WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED     = 0x00000080
	WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION    = 0x00000100
	WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED     = 0x00000200
	WINHTTP_CALLBACK_STATUS_HANDLE_CREATED        = 0x00000400
	WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING        = 0x00000800
	WINHTTP_CALLBACK_STATUS_DETECTING_PROXY       = 0x00001000
	WINHTTP_CALLBACK_STATUS_REDIRECT              = 0x00004000
	WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE = 0x00008000
	WINHTTP_CALLBACK_STATUS_SECURE_FAILURE        = 0x00010000
	WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE     = 0x00020000
	WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE        = 0x00040000
	WINHTTP_CALLBACK_STATUS_READ_COMPLETE         = 0x00080000
	WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE        = 0x00100000
	WINHTTP_CALLBACK_STATUS_REQUEST_ERROR         = 0x00200000
	WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE  = 0x00400000
	WINHTTP_CALLBACK_FLAG_RESOLVE_NAME            = WINHTTP_CALLBACK_STATUS_RESOLVING_NAME | WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
	WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER       = WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER | WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
)
View Source
const (
	WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED        = 0x00000001
	WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT           = 0x00000002
	WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED           = 0x00000004
	WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA             = 0x00000008
	WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID        = 0x00000010
	WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID      = 0x00000020
	WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE       = 0x00000040
	WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR = 0x80000000
)
View Source
const (
	ERROR_INVALID_PARAMETER syscall.Errno = 0x00000057
)

Constants we're missing from the Windows syscall package.

Variables

This section is empty.

Functions

func AddRequestHeaders

func AddRequestHeaders(
	hRequest HInternet,
	header string,
	modifiers uint32,
) error

AddRequestHeaders adds HTTP headers to the specified Request.

func CloseHandle

func CloseHandle(hInternet HInternet)

CloseHandle will close an hInternet handle. It is OK if the handle is already NULL.

func FreeWinHttpCurrentUserIeProxyConfig

func FreeWinHttpCurrentUserIeProxyConfig(cfg *WinHttpCurrentUserIeProxyConfig)

func FreeWinHttpProxyInfo

func FreeWinHttpProxyInfo(cfg *WinHttpProxyInfo)

func QueryDataAvailable

func QueryDataAvailable(
	hRequest HInternet,
) (uint, error)

QueryDataAvailable returns if we have data available to read.

func QueryHeaders

func QueryHeaders(
	hRequest HInternet,
	infoLevel uint32,
	name string,
	buffer *uint16,
	bufferLength *uint32,
	index *uint32,
) error

QueryHeaders retreives information from the headers of the specified Request.

func QueryOption

func QueryOption(
	hInternet HInternet,
	option uint32,
	buffer uintptr,
	bufferLength *uint32,
) error

QueryOption queries an option on the specified handle.

Note that because we don't know what type of data we'll be getting via buffer, this function is tagged with a pragma to behave properly when using the form uintptr(unsafe.Pointer(&obj)) in its function call, similar to the wired-in compiler tricks for syscall.Syscall(). See the documentation to unsafe.Pointer (https://golang.org/pkg/unsafe/#Pointer) for more information.

func ReadData

func ReadData(
	hRequest HInternet,
	buffer []byte,
) (int, error)

ReadData reads data from the Request into buffer.

func ReceiveResponse

func ReceiveResponse(hRequest HInternet) error

ReceiveResponse waits to receive the response to an HTTP request sent by SendRequest.

func SendRequest

func SendRequest(
	hRequest HInternet,
	headers string,
	optional *byte,
	optionalLength int,
	totalLength int,
	context *uint32,
) error

SendRequest sends the given hRequest across the network, with optionally setting additional headers or body data.

func SetOption

func SetOption(
	hInternet HInternet,
	option uint32,
	buffer uintptr,
	bufferLength uintptr,
) error

SetOption sets an option on the specified handle.

Note that because we don't know what type of data we'll be getting via buffer, this function is tagged with a pragma to behave properly when using the form uintptr(unsafe.Pointer(&obj)) in its function call, similar to the wired-in compiler tricks for syscall.Syscall(). See the documentation to unsafe.Pointer (https://golang.org/pkg/unsafe/#Pointer) for more information.

func SetStatusCallback

func SetStatusCallback(
	hInternet HInternet,
	internetCallback interface{},
	notificationFlags uint32,
) error

SetStatusCallback sets a callback for status events from WinHTTP.

See documentation on the callback function signature at https://msdn.microsoft.com/en-us/library/windows/desktop/aa383917(v=vs.85).aspx

func SetTimeouts

func SetTimeouts(
	hInternet HInternet,
	resolveTimeout int,
	connectTimeout int,
	sendTimeout int,
	receiveTimeout int,
) error

Types

type HInternet

type HInternet uintptr

HInternet is an internet handle given to us by WinHttp.

func Connect

func Connect(
	hSession HInternet,
	serverName string,
	port int,
) (HInternet, error)

Connect creates an hConnect handle pointing to a specified server.

func Open

func Open(
	userAgent string,
	accessType uint32,
	proxyName string,
	proxyBypass string,
	flags uint32,
) (HInternet, error)

Open creates a new WinHTTP Session for us.

func OpenRequest

func OpenRequest(
	hConnect HInternet,
	verb string,
	objectName string,
	version string,
	referrer string,
	acceptTypes []string,
	flags uint32,
) (HInternet, error)

OpenRequest creates a new request for a given hConnect.

type WinHttpAutoproxyOptions

type WinHttpAutoproxyOptions struct {
	DwFlags           uint32
	DwAutoDetectFlags uint32
	LpszAutoConfigUrl *uint16

	FAutoLogonIfChallenged bool
	// contains filtered or unexported fields
}

type WinHttpCurrentUserIeProxyConfig

type WinHttpCurrentUserIeProxyConfig struct {
	FAutoDetect       bool
	LpszAutoConfigUrl *uint16
	LpszProxy         *uint16
	LpszProxyBypass   *uint16
}

func GetIEProxyConfigForCurrentUser

func GetIEProxyConfigForCurrentUser() (*WinHttpCurrentUserIeProxyConfig, error)

type WinHttpProxyInfo

type WinHttpProxyInfo struct {
	DwAccessType    uint32
	LpszProxy       *uint16
	LpszProxyBypass *uint16
}

func GetProxyForUrl

func GetProxyForUrl(
	hSession HInternet,
	url string,
	autoProxyOptions *WinHttpAutoproxyOptions,
) (*WinHttpProxyInfo, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL