1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

add 'context.StopWithStatus, StopWithJSON, StopWithProblem' and update the json-struct-validation example

Former-commit-id: dd0347f22324ef4913be284082b8afc6229206a8
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-10 06:04:46 +03:00
parent ad154ea479
commit 978718454a
4 changed files with 129 additions and 51 deletions

View File

@@ -78,7 +78,7 @@ func (p Problem) updateURIsToAbs(ctx Context) {
return
}
if uriRef := p.getURI("type"); uriRef != "" {
if uriRef := p.getURI("type"); uriRef != "" && !strings.HasPrefix(uriRef, "http") {
p.Type(ctx.AbsoluteURI(uriRef))
}
@@ -127,7 +127,7 @@ func (p Problem) Key(key string, value interface{}) Problem {
//
// Empty URI or "about:blank", when used as a problem type,
// indicates that the problem has no additional semantics beyond that of the HTTP status code.
// When "about:blank" is used,
// When "about:blank" is used and "title" was not set-ed,
// the title is being automatically set the same as the recommended HTTP status phrase for that code
// (e.g., "Not Found" for 404, and so on) on `Status` call.
//
@@ -151,15 +151,16 @@ func (p Problem) Title(title string) Problem {
func (p Problem) Status(statusCode int) Problem {
shouldOverrideTitle := !p.keyExists("title")
if !shouldOverrideTitle {
typ, found := p["type"]
shouldOverrideTitle = !found || isEmptyTypeURI(typ.(string))
}
// if !shouldOverrideTitle {
// typ, found := p["type"]
// shouldOverrideTitle = !found || isEmptyTypeURI(typ.(string))
// }
if shouldOverrideTitle {
// Set title by code.
p.Title(http.StatusText(statusCode))
}
return p.Key("status", statusCode)
}