httpclient

package
v0.0.0-...-f61c53a Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpBasicClient

type HttpBasicClient struct {
	// contains filtered or unexported fields
}

HttpBasicClient is the http/2 client for connecting a WoT client to a WoT server using the http-basic protocol profile. This implements the IClientConnection interface.

This can be used alone or with the hiveotsseclient which provides an SSE return channel. This provides authentication methods.

The Forms needed to invoke an operations are obtained using the 'getForm' callback, which can be tied to a store of TD documents. The form contains the hiveot RequestMessage and ResponseMessage endpoints. If no form is available then use the default hiveot endpoints that are defined with this protocol binding.

func NewHttpBasicClient

func NewHttpBasicClient(
	baseURL string, clientID string, clientCert *tls.Certificate, caCert *x509.Certificate,
	getForm messaging.GetFormHandler, timeout time.Duration) *HttpBasicClient

NewHttpBasicClient creates a new instance of the http-basic protocol binding client.

This uses TD forms to perform an operation.

baseURL of the http server. Used as the base for all further requests.
clientID to identify as. Must match the authentication information.
clientCert optional client certificate to connect with, avoiding the need for login.
caCert of the server to validate the server or nil to not check the server cert
getForm is the handler for return a form for invoking an operation. nil for default
timeout for waiting for response. 0 to use the default.

func (*HttpBasicClient) ConnectWithToken

func (cc *HttpBasicClient) ConnectWithToken(token string) error

ConnectWithToken sets the bearer token to use with requests.

func (*HttpBasicClient) Disconnect

func (cc *HttpBasicClient) Disconnect()

Disconnect from the server

func (*HttpBasicClient) GetAppConnectHandler

func (cc *HttpBasicClient) GetAppConnectHandler() messaging.ConnectionHandler

GetAppConnectHandler returns the application handler for connection status updates

func (*HttpBasicClient) GetAppNotificationHandler

func (cc *HttpBasicClient) GetAppNotificationHandler() messaging.NotificationHandler

GetAppNotificationHandler returns the application handler for received notifications

func (*HttpBasicClient) GetAppRequestHandler

func (cc *HttpBasicClient) GetAppRequestHandler() messaging.RequestHandler

GetAppRequestHandler returns the application handler for incoming requests

func (*HttpBasicClient) GetAppResponseHandler

func (cc *HttpBasicClient) GetAppResponseHandler() messaging.ResponseHandler

GetAppResponseHandler set the application handler for received responses

func (*HttpBasicClient) GetConnectionInfo

func (cc *HttpBasicClient) GetConnectionInfo() messaging.ConnectionInfo

GetConnectionInfo returns the client's connection details

func (*HttpBasicClient) GetDefaultForm

func (cc *HttpBasicClient) GetDefaultForm(op, thingID, name string) (f *td.Form)

GetDefaultForm return the default http form for the operation This simply returns nil for anything else than login, logout, ping or refresh.

func (*HttpBasicClient) GetTlsClient

func (cc *HttpBasicClient) GetTlsClient() *http.Client

func (*HttpBasicClient) IsConnected

func (cc *HttpBasicClient) IsConnected() bool

IsConnected return whether the return channel is connection, eg can receive data

func (*HttpBasicClient) Send

func (cc *HttpBasicClient) Send(
	method string, methodPath string, body []byte) (
	resp []byte, headers http.Header, code int, err error)

Send a HTTPS method and return the http response.

If token authentication is enabled then add the bearer token to the header

method: GET, PUT, POST, ...
reqPath: path to invoke
contentType of the payload or "" for default (application/json)
thingID optional path URI variable
name optional path URI variable containing affordance name
body contains the serialized payload
correlationID: optional correlationID header value

This returns the raw serialized response data, a response message ID, return status code or an error

func (*HttpBasicClient) SendNotification

func (cc *HttpBasicClient) SendNotification(msg *messaging.NotificationMessage) error

SendNotification is not supported in http-basic

func (*HttpBasicClient) SendRequest

func (cc *HttpBasicClient) SendRequest(req *messaging.RequestMessage) error

SendRequest sends a request over http message using the form based path and passes the result as a response to the registered response handler.

This locates the form for the operation using 'getForm' and uses the result to determine the URL to publish the request to and if the hiveot RequestMessage envelope is used.

If no form is found then fall back to the hiveot default paths. The request input, if any, is json encoded into the body of the request. This does not use a RequestMessage envelope to remain http-basic compatible.

The response follows the http-basic specification: * code 200: completed; body is output * code 201: pending; body is http action status message * code 40x: failed ; body is error payload, if present * code 50x: failed ; body is error payload, if present

The result is passed to the BaseRnR channel associated with the request just like it is done with an async response.

func (*HttpBasicClient) SendResponse

func (cc *HttpBasicClient) SendResponse(resp *messaging.ResponseMessage) error

SendResponse is not supported in http-basic

func (*HttpBasicClient) SetBearerToken

func (cc *HttpBasicClient) SetBearerToken(token string) error

SetBearerToken sets the authentication bearer token to authenticate http requests.

func (*HttpBasicClient) SetConnectHandler

func (cc *HttpBasicClient) SetConnectHandler(cb messaging.ConnectionHandler)

SetConnectHandler set the application handler for connection status updates

func (*HttpBasicClient) SetConnected

func (cc *HttpBasicClient) SetConnected(isConnected bool)

SetConnected sets the sub-protocol connection status

func (*HttpBasicClient) SetNotificationHandler

func (cc *HttpBasicClient) SetNotificationHandler(cb messaging.NotificationHandler)

SetNotificationHandler set the application handler for received notifications

func (*HttpBasicClient) SetRequestHandler

func (cc *HttpBasicClient) SetRequestHandler(cb messaging.RequestHandler)

SetRequestHandler set the application handler for incoming requests

func (*HttpBasicClient) SetResponseHandler

func (cc *HttpBasicClient) SetResponseHandler(cb messaging.ResponseHandler)

SetResponseHandler set the application handler for received responses

Jump to

Keyboard shortcuts

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