Skip to content

Commit

Permalink
[xnet/xhttp] GetCookie utility function (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kucherenkovova authored Jun 13, 2024
1 parent a9c2e24 commit 7a4dfc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xnet/xhttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Extensions to the standard Go library's `net/http` package. `ListenAndServe` alt

### Install
```
go get github.com/kucherenkovova/gopypaste/xnet/[email protected].2
go get github.com/kucherenkovova/gopypaste/xnet/[email protected].3
```
18 changes: 18 additions & 0 deletions xnet/xhttp/cookie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xhttp

import (
"net/http"
"net/url"
)

// GetCookie returns the unescaped cookie provided in the request or empty string if not found.
func GetCookie(r *http.Request, name string) string {
cookie, err := r.Cookie(name)
if err != nil {
return ""
}

val, _ := url.QueryUnescape(cookie.Value)

return val
}
1 change: 1 addition & 0 deletions xnet/xhttp/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
HeaderOrigin = "Origin"
HeaderReferer = "Referer"
HeaderServer = "Server"
HeaderSetCookie = "Set-Cookie"
HeaderUserAgent = "User-Agent"
HeaderXForwardedFor = "X-Forwarded-For"
)

0 comments on commit 7a4dfc3

Please sign in to comment.