github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/extern/net/http/http.gno (about) 1 package http 2 3 import ( 4 "errors" 5 "io" 6 "time" 7 ) 8 9 //---------------------------------------- 10 // dummy structures to replace net/http Request etc. 11 12 type Header map[string][]string 13 14 // XXX dummy 15 func (h Header) Get(key string) string { 16 return "" 17 } 18 19 type Values map[string][]string 20 21 type Request struct { 22 Method string 23 Proto string // "HTTP/1.0" 24 ProtoMajor int // 1 25 ProtoMinor int // 0 26 Header Header 27 Body io.ReadCloser 28 ContentLength int64 29 TransferEncoding []string 30 Close bool 31 Host string 32 Form Values 33 PostForm Values // Go 1.1 34 Trailer Header 35 RemoteAddr string 36 RequestURI string 37 Response *Response // Go 1.7 38 } 39 40 func (r *Request) UserAgent() string { 41 return r.Header.Get("User-Agent") 42 } 43 44 type Response struct { 45 Status string // e.g. "200 OK" 46 StatusCode int // e.g. 200 47 Proto string // e.g. "HTTP/1.0" 48 ProtoMajor int // e.g. 1 49 ProtoMinor int // e.g. 0 50 } 51 52 type Client struct { 53 Transport RoundTripper 54 Jar CookieJar 55 Timeout time.Duration // Go 1.3 56 } 57 58 // XXX dummy 59 func (c *Client) Get(url string) (resp *Response, err error) { 60 return nil, errors.New("unsupported protocol scheme") 61 } 62 63 type RoundTripper interface { 64 // NOTE: gno2Go doesn't support interfaces. 65 // RoundTrip(*Request) (*Response, error) 66 } 67 68 type Cookie struct { 69 Name string 70 Value string 71 72 Path string // optional 73 Domain string // optional 74 Expires time.Time // optional 75 RawExpires string // for reading cookies only 76 77 // MaxAge=0 means no 'Max-Age' attribute specified. 78 // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0' 79 // MaxAge>0 means Max-Age attribute present and given in seconds 80 MaxAge int 81 Secure bool 82 HttpOnly bool 83 SameSite SameSite // Go 1.11 84 Raw string 85 Unparsed []string // Raw text of unparsed attribute-value pairs 86 } 87 88 type SameSite int 89 90 const ( 91 SameSiteDefaultMode SameSite = iota + 1 92 SameSiteLaxMode 93 SameSiteStrictMode 94 SameSiteNoneMode 95 ) 96 97 type CookieJar interface { 98 // NOTE: gno2Go doesn't support interfaces. 99 // SetCookies(u *url.URL, cookies []*Cookie) 100 // Cookies(u *url.URL) []*Cookie 101 } 102 103 var DefaultClient = &Client{} 104 105 type PushOptions struct { 106 Method string 107 Header Header 108 } 109 110 type Pusher interface { 111 Push(target string, opts *PushOptions) error 112 } 113 114 type ResponseWriter interface { 115 Header() Header 116 Write([]byte) (int, error) 117 WriteHeader(statusCode int) 118 } 119 120 type CloseNotifier interface { 121 CloseNotify() <-chan bool 122 } 123 124 // XXX dummy 125 type Server struct { 126 // Addr optionally specifies the TCP address for the server to listen on, 127 // in the form "host:port". If empty, ":http" (port 80) is used. 128 // The service names are defined in RFC 6335 and assigned by IANA. 129 // See net.Dial for details of the address format. 130 Addr string 131 132 // WriteTimeout is the maximum duration before timing out 133 // writes of the response. It is reset whenever a new 134 // request's header is read. Like ReadTimeout, it does not 135 // let Handlers make decisions on a per-request basis. 136 WriteTimeout time.Duration 137 }