web

Imports

Imports #

"bytes"
"fmt"
"io"
"io/fs"
"net/url"
"strings"
"unicode"
"unicode/utf8"
"errors"
urlpkg "net/url"
"crypto/tls"
"errors"
"fmt"
"io"
"mime"
"net"
"net/http"
urlpkg "net/url"
"os"
"strings"
"time"
"cmd/go/internal/auth"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/web/intercept"
"cmd/internal/browser"
"errors"
"net/url"
"path/filepath"
"strings"
"errors"
"path/filepath"
"errors"
"path/filepath"
"strings"

Constants & Variables

DefaultSecurity const #

const DefaultSecurity

Insecure const #

const Insecure

SecureOnly const #

const SecureOnly SecurityMode = iota

errNotAbsolute var #

var errNotAbsolute = *ast.CallExpr

impatientInsecureHTTPClient var #

impatientInsecureHTTPClient is used with GOINSECURE, when we're connecting to https servers that might not be there or might be using self-signed certificates.

var impatientInsecureHTTPClient = *ast.UnaryExpr

maxErrorDetailBytes const #

const maxErrorDetailBytes = *ast.BinaryExpr

maxErrorDetailLines const #

const maxErrorDetailLines = 8

securityPreservingDefaultClient var #

var securityPreservingDefaultClient = *ast.CallExpr

Type Aliases

SecurityMode type #

SecurityMode specifies whether a function should make network calls using insecure transports (eg, plain text HTTP). The zero value is "secure".

type SecurityMode int

Structs

HTTPError struct #

An HTTPError describes an HTTP error response (non-200 result).

type HTTPError struct {
URL string
Status string
StatusCode int
Err error
Detail string
}

Response struct #

type Response struct {
URL string
Status string
StatusCode int
Header map[string][]string
Body io.ReadCloser
fileErr error
errorDetail errorDetailBuffer
}

errorDetailBuffer struct #

An errorDetailBuffer is an io.ReadCloser that copies up to maxErrorDetailLines into a buffer for later inspection.

type errorDetailBuffer struct {
r io.ReadCloser
buf strings.Builder
bufLines int
}

hookCloser struct #

type hookCloser struct {
io.ReadCloser
afterClose func()
}

Functions

Close method #

func (c hookCloser) Close() error

Close method #

func (b *errorDetailBuffer) Close() error

Err method #

Err returns an *HTTPError corresponding to the response r. If the response r has StatusCode 200 or 0 (unset), Err returns nil. Otherwise, Err may read from r.Body in order to extract relevant error detail.

func (r *Response) Err() error

Error method #

func (e *HTTPError) Error() string

Get function #

Get returns the body of the HTTP or HTTPS resource specified at the given URL. If the URL does not include an explicit scheme, Get first tries "https". If the server does not respond under that scheme and the security mode is Insecure, Get then tries "http". The URL included in the response indicates which scheme was actually used, and it is a redacted URL suitable for use in error messages. For the "https" scheme only, credentials are attached using the cmd/go/internal/auth package. If the URL itself includes a username and password, it will not be attempted under the "http" scheme unless the security mode is Insecure. Get returns a non-nil error only if the request did not receive a response under any applicable scheme. (A non-2xx response does not cause an error.)

func Get(security SecurityMode, u *url.URL) (*Response, error)

GetBytes function #

GetBytes returns the body of the requested resource, or an error if the response status was not http.StatusOK. GetBytes is a convenience wrapper around Get and Response.Err.

func GetBytes(u *url.URL) ([]byte, error)

Is method #

func (e *HTTPError) Is(target error) bool

IsLocalHost function #

IsLocalHost reports whether the given URL refers to a local (loopback) host, such as "localhost" or "127.0.0.1:8080".

func IsLocalHost(u *url.URL) bool

Join function #

Join returns the result of adding the slash-separated path elements to the end of u's path.

func Join(u *url.URL, path string) *url.URL

OpenBrowser function #

OpenBrowser attempts to open the requested URL in a web browser.

func OpenBrowser(url string) (opened bool)

Read method #

func (b *errorDetailBuffer) Read(p []byte) (n int, err error)

Unwrap method #

func (e *HTTPError) Unwrap() error

checkRedirect function #

func checkRedirect(req *http.Request, via []*http.Request) error

convertFileURLPath function #

func convertFileURLPath(host string, path string) (string, error)

convertFileURLPath function #

func convertFileURLPath(host string, path string) (string, error)

formatErrorDetail method #

formatErrorDetail converts r.errorDetail (a prefix of the output of r.Body) into a short, tab-indented summary.

func (r *Response) formatErrorDetail() string

get function #

func get(security SecurityMode, url *urlpkg.URL) (*Response, error)

get function #

func get(security SecurityMode, url *urlpkg.URL) (*Response, error)

getFile function #

func getFile(u *urlpkg.URL) (*Response, error)

isLocalHost function #

func isLocalHost(u *urlpkg.URL) bool

isLocalHost function #

func isLocalHost(u *urlpkg.URL) bool

openBrowser function #

func openBrowser(url string) bool

openBrowser function #

func openBrowser(url string) bool

securityPreservingHTTPClient function #

securityPreservingHTTPClient returns a client that is like the original but rejects redirects to plain-HTTP URLs if the original URL was secure.

func securityPreservingHTTPClient(original *http.Client) *http.Client

urlFromFilePath function #

func urlFromFilePath(path string) (*url.URL, error)

urlToFilePath function #

func urlToFilePath(u *url.URL) (string, error)

Generated with Arrow