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
Compare revisions
v1.0.1 to v1.0.2
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
oss/libraries/go/network/http-negotiation
Select target project
No results found
v1.0.2
Select Git revision
Swap
Target
oss/libraries/go/network/http-negotiation
Select target project
oss/libraries/go/network/http-negotiation
1 result
v1.0.1
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
add documentation
· 1b336cc0
Volker Schukai
authored
2 years ago
1b336cc0
Bump version to 1.0.2
· f9c41f1f
Volker Schukai
authored
2 years ago
f9c41f1f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+74
-1
74 additions, 1 deletion
README.md
release.json
+1
-1
1 addition, 1 deletion
release.json
with
75 additions
and
2 deletions
README.md
View file @
f9c41f1f
...
...
@@ -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.
release.json
View file @
f9c41f1f
{
"version"
:
"1.0.
1
"
}
{
"version"
:
"1.0.
2
"
}
This diff is collapsed.
Click to expand it.