github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/protocol/http.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package protocol
     4  
     5  // HTTPHandler is any object to be HTTP service handler.
     6  type HTTPHandler interface {
     7  	ServeHTTP(stream Stream, httpReq HTTPRequest, httpRes HTTPResponse) (err Error)
     8  }
     9  
    10  // HTTP Request Semantic
    11  type HTTPRequest interface {
    12  	// "message start-line" in HTTP/1.x or "pseudo-header fields" in HTTP/2.x||HTTP/3.x
    13  	Method() string
    14  	URI() HTTPURI
    15  	Version() string
    16  	SetMethod(method string)
    17  	SetVersion(version string)
    18  
    19  	Header() HTTPHeader
    20  	HTTPBody
    21  
    22  	Codec
    23  }
    24  
    25  // HTTP Response Semantic
    26  type HTTPResponse interface {
    27  	// "message start-line" in HTTP/1.x or "pseudo-header fields" in HTTP/2.x||HTTP/3.x
    28  	Version() string
    29  	StatusCode() string
    30  	ReasonPhrase() string
    31  	SetVersion(version string)
    32  	SetStatus(statusCode, reasonPhrase string)
    33  
    34  	Header() HTTPHeader
    35  	HTTPBody
    36  
    37  	Codec
    38  }
    39  
    40  // HTTP URI Semantic
    41  type HTTPURI interface {
    42  	URI
    43  	// URI() string    // always return full http URI
    44  	// Scheme() string // always return "http" or "https"
    45  	Authority() string
    46  	Host() string
    47  	Path() string
    48  	Query() string
    49  	Fragment() string
    50  	Set(scheme, authority, path, query string)
    51  }
    52  
    53  // HTTP Header Semantic
    54  type HTTPHeader interface {
    55  	Get(key string) (value string)
    56  	Gets(key string) (values []string)
    57  	Add(key, value string)
    58  	Adds(key string, values []string)
    59  	Set(key string, value string)
    60  	Sets(key string, values []string)
    61  	Del(key string)
    62  }
    63  
    64  // HTTP Body Semantic
    65  type HTTPBody interface {
    66  	Body() Codec
    67  	SetBody(codec Codec)
    68  }