rapic

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

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 14 Imported by: 0

README

[WIP] RAPIC

Coverage Go Report Card Licence Go Doc

A lightweight API-oriented HTTP client

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthDigest

type AuthDigest struct {
	// The default algorithm used is DIGEST_SHA256
	Algorithm DigestAlgo

	Realm    string
	URI      string
	QOP      string
	Nonce    string
	CNonce   string
	NC       string
	UserHash bool
	Opaque   string
}

AuthDigest is the available Authorization Digest Setting Field Defined under RFC7616-3.4 at https://datatracker.ietf.org/doc/html/rfc7616#section-3.4

func (*AuthDigest) Build

func (d *AuthDigest) Build(user, password string, body *string, method RequestMethods) string

Build is the Digest Access Authentication builder Generate a valid Digest header value in accordance with the RFC7616 But retains backwards compatibility with the RFC2069

Suppose you have filled the information in AuthDigest{}

func (*AuthDigest) Hash

func (d *AuthDigest) Hash(s string) (hashed string)

Hash is the hashing function for Digest Access Authentication AuthDigest can be used with Algorithm - MD5 (RFC2069 and RFC2617) - SHA-256 (RFC7616) - SHA-512-256 (RFC7616) - SHA-512 (for futureproof)

type AuthScheme

type AuthScheme string
const (
	AUTH_BASIC  AuthScheme = "Basic"
	AUTH_BEARER AuthScheme = "Bearer"
	AUTH_DIGEST AuthScheme = "Digest"
	AUTH_CUSTOM AuthScheme = "Custom"
)

type Authorization

type Authorization struct {
	Scheme AuthScheme

	Username string
	Password string

	// Only for Bearer auth
	Token string

	// Only for Digest auth.
	Digest AuthDigest

	// The value for Custom auth
	Value string
}

type Client

type Client struct {
	Settings Settings

	URL   *url.URL
	Query url.Values

	Header http.Header
	Cookie CookieJar

	Authorization Authorization
}

func New

func New(endpoint string, auth ...Authorization) (main Client, err error)

New return an initialized Client struct. This is the main client, you can make request from it or create children for new request with their inheritance

This function require a Endpoint URL with scheme Path. You can also specify a Auth with the optinal Authorization arg

func (*Client) FlushHeader

func (c *Client) FlushHeader()

FlushHeader remove all stored header

func (*Client) FlushQuery

func (c *Client) FlushQuery()

FlushQuery remove all stored query

func (*Client) NewChild

func (parent *Client) NewChild(path ...string) (child Client)

NewChild create a children client with parent inheritance. This new client are isolated from the parent.

Can take a relative path from parent

func (*Client) Request

func (c *Client) Request(method RequestMethods, body *string, res *http.Response) (err error)

TODO

type Cookie struct {
	Name   string
	Value  string
	Path   string
	Domain string
}

type CookieJar

type CookieJar struct {
	http.CookieJar
}

func (*CookieJar) Add

func (j *CookieJar) Add(URL string, new ...*http.Cookie) error

AddCookie adds the key, value pair to the cookie Jar. It does nothing if the URL's scheme is not HTTP or HTTPS.

func (*CookieJar) Clear

func (j *CookieJar) Clear() (err error)

Clear deletes ALL cookie entries in Jar.

func (*CookieJar) Del

func (j *CookieJar) Del(URL string, name string) error

Del deletes all cookie entries associated with the given key name in Jar. It does nothing if the URL's scheme is not HTTP or HTTPS.

func (*CookieJar) Get

func (j *CookieJar) Get(URL string, name string) (*http.Cookie, error)

Get the first cookie associated with the given key. If there are no values associated with the key, Get returns a empty http.Cookie It does nothing if the URL's scheme is not HTTP or HTTPS.

func (*CookieJar) Set

func (j *CookieJar) Set(URL string, c *http.Cookie) error

Set the cookie entries associated with the given key to the element value. It replaces any existing values associated with the given key in Jar. It does nothing if the URL's scheme is not HTTP or HTTPS.

type DigestAlgo

type DigestAlgo string

DigestAlgo is Hash Algorithms for HTTP Digest Authentication But add SHA512 support to be futureproof Defined under RFC7616-6.1 at https://datatracker.ietf.org/doc/html/rfc7616#section-6.1

const (
	DIGEST_MD5       DigestAlgo = "md5"
	DIGEST_SHA256    DigestAlgo = "sha-256"
	DIGEST_SHA512    DigestAlgo = "sha-512"
	DIGEST_SHA512256 DigestAlgo = "sha-512-256"

	DIGEST_MD5_SESS       DigestAlgo = "md5-sess"
	DIGEST_SHA256_SESS    DigestAlgo = "sha-256-sess"
	DIGEST_SHA512_SESS    DigestAlgo = "sha-512-sess"
	DIGEST_SHA512256_SESS DigestAlgo = "sha-512-256-sess"
)

type RequestMethods

type RequestMethods string
const (
	METHOD_CONNECT RequestMethods = "CONNECT"
	METHOD_DELETE  RequestMethods = "DELETE"
	METHOD_GET     RequestMethods = "GET"
	METHOD_HEAD    RequestMethods = "HEAD"
	METHOD_OPTIONS RequestMethods = "OPTIONS"
	METHOD_PATCH   RequestMethods = "PATCH"
	METHOD_POST    RequestMethods = "POST"
	METHOD_PUT     RequestMethods = "PUT"
	METHOD_TRACE   RequestMethods = "TRACE"
)

type Response

type Response struct {
}

TODO

type Settings

type Settings struct {
	// Follow is for auto follow the HTTP 3xx as redirects (def: true)
	Follow bool
	// FollowAuth Keep authorization header when redirect to a different host (def: false)
	FollowAuth bool
	// FollowReferer keep the referer header when a redirect happens (def: true)
	FollowReferer bool
	// MaxRedirect to set the maximum number of redirects to follow (def: 2)
	MaxRedirect uint8
	// AutoCookie store automatically cookie's if a set-cookie is found in header (def: true)
	AutoCookie bool
	// Retry if request is not 2xx or 3xx (def: true)
	Retry bool
	// MaxRetry to set the maximum number of retry (def: 1)
	MaxRetry uint8
	// WaitRetry to set the time to wait before retry in second (def: 10)
	WaitRetry time.Duration
}

Jump to

Keyboard shortcuts

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