diff --git a/req_header.go b/req_header.go deleted file mode 100644 index 97de137..0000000 --- a/req_header.go +++ /dev/null @@ -1,74 +0,0 @@ -package minima - -/** -* Minima is a free and open source software under Mit license - -Copyright (c) 2021 gominima - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -* Authors @apoorvcodes @megatank58 -* Maintainers @Panquesito7 @savioxavier @Shubhaankar-Sharma @apoorvcodes @megatank58 -* Thank you for showing interest in minima and for this beautiful community -*/ - -/** - * @info The request headers structure - * @property {string} [key] Key for the header - * @property {string} [value] Value of the header - */ -type ReqHeader struct { - key string - value string -} - -/** - * @info The Incoming header structure - * @property {[]*ReqHeader} [headers] Array of request headers - */ -type IncomingHeader struct { - headers []*ReqHeader -} - -/** - * @info Gets request header from given key - * @property {string} [key] Key for the header -return {string} -*/ -func (h IncomingHeader) Get(key string) string { - var value string - - for _, v := range h.headers { - if v.key == key { - value = v.value - break - } - } - - return value -} - -/** - * @info Declares request header from given key - * @property {string} [key] Key for the header - * @property {string} [value] Value of the header - */ -func (h *IncomingHeader) Set(key string, v string) { - h.headers = append(h.headers, &ReqHeader{key: key, value: v}) -} diff --git a/request.go b/request.go index f42106f..282aabf 100644 --- a/request.go +++ b/request.go @@ -45,7 +45,6 @@ import ( * @property {string} [method] Request method * @property {[]*Params} [Params] Request path parameters * @property {query} [url.Values] Request path query params - * @property {IncomingHeader} [header] Incoming headers of the request * @property {json.Decoder} [json] Json decoder instance */ type Request struct { @@ -54,7 +53,6 @@ type Request struct { body map[string][]string method string Params map[string]string - header *IncomingHeader json *json.Decoder } @@ -66,16 +64,11 @@ type Request struct { func request(r *http.Request) *Request { req := &Request{ ref: r, - header: &IncomingHeader{}, fileReader: nil, method: r.Proto, } - for i, v := range r.Header { - req.header.Set(strings.ToLower(i), strings.Join(v, ",")) - } - - if req.header.Get("content-type") == "application/json" { + if req.ref.Header.Get("content-type") == "application/json" { req.json = json.NewDecoder(r.Body) } else { r.ParseForm() @@ -321,7 +314,7 @@ func (r *Request) GetCookie(key string) *http.Cookie { * @returns {*Request} */ func (r *Request) SetHeader(key string, value string) *Request { - r.header.Set(key, value) + r.ref.Header.Set(key, value) return r } @@ -331,5 +324,22 @@ func (r *Request) SetHeader(key string, value string) *Request { * @returns {string} */ func (r *Request) GetHeader(key string) string { - return r.header.Get(key) + return r.ref.Header.Get(key) +} + + +/** + * @info Deletes a paticular Header by its key + * @param {string} [key] key of the Header + */ + func (r *Request) DelHeader(key string) { + r.ref.Header.Del(key) +} + +/** + * @info Clones all headers from request body + * @returns {http.Header} + */ + func (r *Request) CloneHeader() http.Header { + return r.ref.Header.Clone() }