github.com/aacfactory/fns@v1.2.86-0.20240310083819-80d667fc0a17/transports/fast/request.go (about)

     1  /*
     2   * Copyright 2023 Wang Min Xiang
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   * 	http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   */
    17  
    18  package fast
    19  
    20  import (
    21  	"crypto/tls"
    22  	"github.com/aacfactory/fns/commons/bytex"
    23  	"github.com/aacfactory/fns/transports"
    24  )
    25  
    26  type Request struct {
    27  	*Context
    28  }
    29  
    30  func (r *Request) TLS() bool {
    31  	return r.Context.IsTLS()
    32  }
    33  
    34  func (r *Request) TLSConnectionState() *tls.ConnectionState {
    35  	return r.Context.TLSConnectionState()
    36  }
    37  
    38  func (r *Request) RemoteAddr() []byte {
    39  	return bytex.FromString(r.Context.RemoteAddr().String())
    40  }
    41  
    42  func (r *Request) Proto() []byte {
    43  	return r.Context.Request.Header.Protocol()
    44  }
    45  
    46  func (r *Request) Host() []byte {
    47  	return r.Context.Host()
    48  }
    49  
    50  func (r *Request) Method() []byte {
    51  	return r.Context.Method()
    52  }
    53  
    54  func (r *Request) SetMethod(method []byte) {
    55  	r.Context.Request.Header.SetMethodBytes(method)
    56  }
    57  
    58  func (r *Request) Cookie(key []byte) (value []byte) {
    59  	value = r.Context.Request.Header.CookieBytes(key)
    60  	return
    61  }
    62  
    63  func (r *Request) SetCookie(key []byte, value []byte) {
    64  	r.Context.Request.Header.SetCookieBytesKV(key, value)
    65  }
    66  
    67  func (r *Request) Header() transports.Header {
    68  	return RequestHeader{
    69  		ctx: r.Context.RequestCtx,
    70  	}
    71  }
    72  
    73  func (r *Request) RequestURI() []byte {
    74  	return r.Context.RequestURI()
    75  }
    76  
    77  func (r *Request) Path() []byte {
    78  	return r.Context.URI().Path()
    79  }
    80  
    81  func (r *Request) Params() transports.Params {
    82  	return &Params{args: r.Context.QueryArgs()}
    83  }
    84  
    85  func (r *Request) FormValue(name []byte) (value []byte) {
    86  	return r.Context.FormValue(string(name))
    87  }
    88  
    89  func (r *Request) Body() ([]byte, error) {
    90  	return r.Context.PostBody(), nil
    91  }
    92  
    93  func (r *Request) SetBody(body []byte) {
    94  	r.Context.Request.SetBody(body)
    95  }