github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/net/http/request_http.go (about) 1 // SPDX-License-Identifier: ice License 1.0 2 3 package http 4 5 import "net/http" 6 7 func (r *Request) toHttp() *http.Request { 8 req := &http.Request{ 9 Method: r.Method, 10 URL: r.URL, 11 Proto: r.Proto, 12 ProtoMajor: r.ProtoMajor, 13 ProtoMinor: r.ProtoMinor, 14 Header: r.Header.toHttp(), 15 Body: r.Body, 16 GetBody: r.GetBody, 17 ContentLength: r.ContentLength, 18 TransferEncoding: r.TransferEncoding, 19 Close: r.Close, 20 Host: r.Host, 21 Form: r.Form, 22 PostForm: r.PostForm, 23 MultipartForm: r.MultipartForm, 24 Trailer: r.Trailer.toHttp(), 25 RemoteAddr: r.RemoteAddr, 26 RequestURI: r.RequestURI, 27 TLS: r.TLS, 28 Cancel: r.Cancel, 29 } 30 if r.Response != nil { 31 req.Response = r.Response.toHttp(req) 32 } 33 return req 34 } 35 36 func (r *Response) toHttp(req *http.Request) *http.Response { 37 res := &http.Response{ 38 Status: r.Status, 39 StatusCode: r.StatusCode, 40 Proto: r.Proto, 41 ProtoMajor: r.ProtoMajor, 42 ProtoMinor: r.ProtoMinor, 43 Body: r.Body, 44 ContentLength: r.ContentLength, 45 TransferEncoding: r.TransferEncoding, 46 Close: r.Close, 47 Uncompressed: r.Uncompressed, 48 Request: req, 49 TLS: r.TLS, 50 } 51 if r.Header != nil { 52 req.Header = r.Header.toHttp() 53 } 54 if r.Trailer != nil { 55 req.Trailer = r.Trailer.toHttp() 56 } 57 return res 58 } 59 60 func (h Header) toHttp() http.Header { 61 if len(h) == 0 { 62 return make(http.Header) 63 } 64 return http.Header(h) 65 }