Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
HTTP Negotiation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Network
HTTP Negotiation
Commits
1b336cc0
Verified
Commit
1b336cc0
authored
2 years ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
add documentation
parent
b4802679
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+74
-1
74 additions, 1 deletion
README.md
with
74 additions
and
1 deletion
README.md
+
74
−
1
View file @
1b336cc0
...
...
@@ -21,12 +21,16 @@ It supports:
## Usage
### Content Negotiation
With the
`Type`
function you can negotiate the content type of HTTP request.
```
go
package
main
import
(
"net/http"
"gitlab.schukai.com/oss/libraries/go/
application
/http-negotiation"
"gitlab.schukai.com/oss/libraries/go/
network
/http-negotiation"
)
func
handleRequest
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -42,6 +46,75 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
```
### Language Negotiation
With the
`Language`
function you can negotiate the language of HTTP request.
```
go
package
main
import
(
"net/http"
"gitlab.schukai.com/oss/libraries/go/network/http-negotiation"
)
func
handleRequest
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
n
:=
negotiation
.
New
(
r
.
Header
)
if
n
.
Language
(
"en-GB"
,
"en"
)
!=
"en"
{
// ...
}
}
```
### Charset Negotiation
With the
`Charset`
function you can negotiate the charset of HTTP request.
```
go
package
main
import
(
"net/http"
"gitlab.schukai.com/oss/libraries/go/network/http-negotiation"
)
func
handleRequest
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
n
:=
negotiation
.
New
(
r
.
Header
)
if
n
.
Charset
(
"utf-8"
,
"iso-8859-1"
)
!=
"utf-8"
{
// ...
}
}
```
### Encoding Negotiation
With the
`Encoding`
function you can negotiate the encoding of HTTP request.
```
go
package
main
import
(
"net/http"
"gitlab.schukai.com/oss/libraries/go/network/http-negotiation"
)
func
handleRequest
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
n
:=
negotiation
.
New
(
r
.
Header
)
if
n
.
Encoding
(
"gzip"
,
"deflate"
)
!=
"gzip"
{
// ...
}
}
```
## Contributing
Merge requests are welcome. For major changes, please open an issue first to discuss what
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment