Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • oss/libraries/go/network/http-negotiation
1 result
Select Git revision
Show changes
Commits on Source (2)
......@@ -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
......
{"version":"1.0.1"}
{"version":"1.0.2"}