mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Add context#IsMobile
Former-commit-id: 571ad7c7a2baf4ec58ba6395003aa9c3bedd1f73
This commit is contained in:
commit
e02da3d442
|
@ -382,7 +382,12 @@ type Context interface {
|
|||
// Read more at: https://developer.mozilla.org/en-US/docs/AJAX
|
||||
// and https://xhr.spec.whatwg.org/
|
||||
IsAjax() bool
|
||||
|
||||
// IsMobile checks if client is using a mobile device(phone or tablet) to communicate with this server.
|
||||
// If the return value is true that means that the http client using a mobile
|
||||
// device to communicate with the server, otherwise false.
|
||||
//
|
||||
// Keep note that this checks the "User-Agent" request header.
|
||||
IsMobile() bool
|
||||
// +------------------------------------------------------------+
|
||||
// | Response Headers helpers |
|
||||
// +------------------------------------------------------------+
|
||||
|
@ -1316,6 +1321,18 @@ func (ctx *context) IsAjax() bool {
|
|||
return ctx.GetHeader("X-Requested-With") == "XMLHttpRequest"
|
||||
}
|
||||
|
||||
var isMobileRegex = regexp.MustCompile(`(?i)(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)`)
|
||||
|
||||
// IsMobile checks if client is using a mobile device(phone or tablet) to communicate with this server.
|
||||
// If the return value is true that means that the http client using a mobile
|
||||
// device to communicate with the server, otherwise false.
|
||||
//
|
||||
// Keep note that this checks the "User-Agent" request header.
|
||||
func (ctx *context) IsMobile() bool {
|
||||
s := ctx.GetHeader("User-Agent")
|
||||
return isMobileRegex.MatchString(s)
|
||||
}
|
||||
|
||||
// +------------------------------------------------------------+
|
||||
// | Response Headers helpers |
|
||||
// +------------------------------------------------------------+
|
||||
|
|
Loading…
Reference in New Issue
Block a user