github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/http.go (about) 1 /* For license and copyright information please see the LEGAL file in the code 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 // ServeGoHTTP(httpRes http.ResponseWriter, httpReq *http.Request) Due to bad sign, we can't standard it here. 9 10 // Call service remotely by HTTP protocol 11 // doHTTP(req any) (res any, err Error) Due to specific sign for each service, we can't standard it here. 12 } 13 14 // HTTPRequest indicate request semantic. 15 type HTTPRequest interface { 16 HTTP_PseudoHeader_Request 17 Header() HTTPHeader 18 HTTPBody 19 20 Codec 21 } 22 23 // HTTPResponse indicate response semantic. 24 type HTTPResponse interface { 25 HTTP_PseudoHeader_Response 26 Header() HTTPHeader 27 HTTPBody 28 29 Codec 30 } 31 32 // HTTP_PseudoHeader_Request indicate request pseudo header. 33 // "message start-line" in HTTP/1.x or "pseudo-header fields" in HTTP/2.x||HTTP/3.x 34 type HTTP_PseudoHeader_Request interface { 35 Method() string 36 // https://datatracker.ietf.org/doc/html/rfc2616#section-3.2 37 // http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] 38 // .Scheme() string // always return "http" 39 URI() URI 40 Version() string 41 42 SetMethod(method string) 43 SetVersion(version string) 44 } 45 46 // HTTP_PseudoHeader_Response indicate response pseudo header. 47 // "message start-line" in HTTP/1.x or "pseudo-header fields" in HTTP/2.x||HTTP/3.x 48 type HTTP_PseudoHeader_Response interface { 49 Version() string 50 StatusCode() string 51 ReasonPhrase() string 52 53 SetVersion(version string) 54 SetStatus(statusCode, reasonPhrase string) 55 } 56 57 // HTTPHeader indicate HTTP header semantic. 58 type HTTPHeader interface { 59 Get(key string) (value string) 60 Gets(key string) (values []string) 61 Add(key, value string) 62 Adds(key string, values []string) 63 Set(key string, value string) 64 Sets(key string, values []string) 65 Del(key string) 66 } 67 68 // HTTP Body Semantic 69 type HTTPBody interface { 70 Body() Codec 71 SetBody(codec Codec) 72 }