// Post posts an HTTP request. The HTTP request is first signed and the signature is added to the request header.
Post posts an HTTP request. The HTTP request is first signed and the signature is added to the request header.
// Post posts an HTTP request . The HTTP request is first signed and the signature is added to the request header .
func (t *Transport) Post(ctx context.Context, r *Request, payload []byte) (*http.Response, error) {
	var body io.Reader
	if len(payload) > 0 {
		body = bytes.NewBuffer(payload)
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodPost, r.URL.String(), body)
	if err != nil {
		return nil, fmt.Errorf("new request to %s: %w", r.URL, err)
	}
	for k, v := range r.Header {
		req.Header[k] = v
	}
	authRequired, err := t.tokenMgr.IsAuthRequired(r.URL.Path, http.MethodPost)
	if err != nil {
		return nil, fmt.Errorf("is authorization required: %w", err)
	}
	if authRequired {
		err = t.postSigner.SignRequest(t.publicKeyID.String(), req)
		if err != nil {
			return nil, fmt.Errorf("sign request: %w", err)
		}
		logger.Debugf("Signed HTTP POST to %s. Headers: %s", r.URL, req.Header)
	} else {
		logger.Debugf("HTTP signature is not required for HTTP POST to %s", r.URL)
	}
	return t.client.Do(req)
}
func ( t * Transport ) Post ( ctx context . Context , r * Request , payload [ ] byte ) ( * http . Response , error ) { var body io . Reader if len ( payload ) > 0 { body = bytes . NewBuffer ( payload ) } req , err := http . NewRequestWithContext ( ctx , http . MethodPost , r . URL . String ( ) , body ) if err != nil { return nil , fmt . Errorf ( " " , r . URL , err ) } for k , v := range r . Header { req . Header [ k ] = v } authRequired , err := t . tokenMgr . IsAuthRequired ( r . URL . Path , http . MethodPost ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if authRequired { err = t . postSigner . SignRequest ( t . publicKeyID . String ( ) , req ) if err != nil { return nil , fmt . Errorf ( " " , err ) } logger . Debugf ( " " , r . URL , req . Header ) } else { logger . Debugf ( " " , r . URL ) } return t . client . Do ( req ) }
Post posts an HTTP request.
Post posts an HTTP request .