mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-19 16:25:30 +00:00
* prototype errkit * complete errkit implementation * add cause to all timeouts * fix request timeout annotation @timeout * increase responseHeaderTimeout to 8 for stability * rawhttp error related improvements * feat: add port status caching * add port status caching to http * migrate to new utils/errkit * remote dialinterface + error cause * debug dir support using .gitignore debug-* * make nuclei easy to debug * debug dir update .gitignore * temp change (to revert) * Revert "temp change (to revert)" This reverts commit d3131f777713b9f80e2275142e80f36340a76d36. * use available context instead of new one * bump fastdialer * fix hosterrorscache + misc improvements * add 'address' field in error log * fix js vague errors + pgwrap driver * fix max host error + misc updates * update tests as per changes * fix request annotation context * remove closed dialer reference * fix sdk panic issue * bump retryablehttp-go,utils,fastdialer --------- Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package pgwrap
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/lib/pq"
|
|
"github.com/projectdiscovery/fastdialer/fastdialer"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
|
)
|
|
|
|
const (
|
|
PGWrapDriver = "pgwrap"
|
|
)
|
|
|
|
type pgDial struct {
|
|
fd *fastdialer.Dialer
|
|
}
|
|
|
|
func (p *pgDial) Dial(network, address string) (net.Conn, error) {
|
|
return p.fd.Dial(context.TODO(), network, address)
|
|
}
|
|
|
|
func (p *pgDial) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
|
|
ctx, cancel := context.WithTimeoutCause(context.Background(), timeout, fastdialer.ErrDialTimeout)
|
|
defer cancel()
|
|
return p.fd.Dial(ctx, network, address)
|
|
}
|
|
|
|
func (p *pgDial) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
|
return p.fd.Dial(ctx, network, address)
|
|
}
|
|
|
|
// Unfortunately lib/pq does not provide easy to customize or
|
|
// replace dialer so we need to hijack it by wrapping it in our own
|
|
// driver and register it as postgres driver
|
|
|
|
// PgDriver is the Postgres database driver.
|
|
type PgDriver struct{}
|
|
|
|
// Open opens a new connection to the database. name is a connection string.
|
|
// Most users should only use it through database/sql package from the standard
|
|
// library.
|
|
func (d PgDriver) Open(name string) (driver.Conn, error) {
|
|
return pq.DialOpen(&pgDial{fd: protocolstate.Dialer}, name)
|
|
}
|
|
|
|
func init() {
|
|
sql.Register(PGWrapDriver, &PgDriver{})
|
|
}
|