Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
162bee1b
authored
2015-03-26 21:50:41 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #1095 from byrnedo/develop
Added AcceptHtml/Json/Xml function to input
2 parents
8aa94559
533b00ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
context/input.go
context/input.go
View file @
162bee1
...
...
@@ -21,12 +21,21 @@ import (
"net/http"
"net/url"
"reflect"
"regexp"
"strconv"
"strings"
"github.com/astaxie/beego/session"
)
// Regexes for checking the accept headers
// TODO make sure these are correct
var
(
acceptsHtmlRegex
=
regexp
.
MustCompile
(
`(text/html|application/xhtml\+xml)(?:,|$)`
)
acceptsXmlRegex
=
regexp
.
MustCompile
(
`(application/xml|text/xml)(?:,|$)`
)
acceptsJsonRegex
=
regexp
.
MustCompile
(
`(application/json)(?:,|$)`
)
)
// BeegoInput operates the http request header, data, cookie and body.
// it also contains router params and current session.
type
BeegoInput
struct
{
...
...
@@ -163,6 +172,21 @@ func (input *BeegoInput) IsUpload() bool {
return
strings
.
Contains
(
input
.
Header
(
"Content-Type"
),
"multipart/form-data"
)
}
// Checks if request accepts html response
func
(
input
*
BeegoInput
)
AcceptsHtml
()
bool
{
return
acceptsHtmlRegex
.
MatchString
(
input
.
Header
(
"Accept"
))
}
// Checks if request accepts xml response
func
(
input
*
BeegoInput
)
AcceptsXml
()
bool
{
return
acceptsXmlRegex
.
MatchString
(
input
.
Header
(
"Accept"
))
}
// Checks if request accepts json response
func
(
input
*
BeegoInput
)
AcceptsJson
()
bool
{
return
acceptsJsonRegex
.
MatchString
(
input
.
Header
(
"Accept"
))
}
// IP returns request client ip.
// if in proxy, return first proxy id.
// if error, return 127.0.0.1.
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment