Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
fix response types
Browse files Browse the repository at this point in the history
  • Loading branch information
farshidtz committed Apr 29, 2021
1 parent 1886794 commit d67bb61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
6 changes: 2 additions & 4 deletions catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
type ThingDescription = map[string]interface{}

const (
ResponseContextURL = "https://linksmart.eu/thing-directory/context.jsonld"
ResponseType = "Catalog"
ResponseMediaType = "application/ld+json"
ResponseJSONMediaType = "application/json"
ResponseContextURL = "https://linksmart.eu/thing-directory/context.jsonld"
ResponseType = "Catalog"
// DNS-SD
DNSSDServiceType = "_wot._tcp"
DNSSDServiceSubtype = "_directory" // _directory._sub._wot._tcp
Expand Down
23 changes: 8 additions & 15 deletions catalog/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,12 @@ type ValidationResult struct {
}

type HTTPAPI struct {
controller CatalogController
contentType string
controller CatalogController
}

func NewHTTPAPI(controller CatalogController, version string) *HTTPAPI {
contentType := ResponseMediaType
if version != "" {
contentType += ";version=" + version
}
return &HTTPAPI{
controller: controller,
contentType: contentType,
controller: controller,
}
}

Expand Down Expand Up @@ -149,7 +143,6 @@ func (a *HTTPAPI) Put(w http.ResponseWriter, req *http.Request) {
return
}
}
w.Header().Set("Content-Type", a.contentType)
w.Header().Set("Location", id)
w.WriteHeader(http.StatusCreated)
return
Expand Down Expand Up @@ -235,7 +228,7 @@ func (a *HTTPAPI) Get(w http.ResponseWriter, req *http.Request) {
return
}

w.Header().Set("Content-Type", a.contentType)
w.Header().Set("Content-Type", wot.MediaTypeThingDescription)
_, err = w.Write(b)
if err != nil {
log.Printf("ERROR writing HTTP response: %s", err)
Expand Down Expand Up @@ -339,7 +332,7 @@ func (a *HTTPAPI) GetMany(w http.ResponseWriter, req *http.Request) {
return
}

w.Header().Set("Content-Type", a.contentType)
w.Header().Set("Content-Type", wot.MediaTypeJSONLD)
w.Header().Set("X-Request-URL", req.RequestURI)
_, err = w.Write(b)
if err != nil {
Expand All @@ -354,7 +347,7 @@ func (a *HTTPAPI) GetAll(w http.ResponseWriter, req *http.Request) {
// panic("expected http.ResponseWriter to be an http.Flusher")
//}

w.Header().Set("Content-Type", a.contentType)
w.Header().Set("Content-Type", wot.MediaTypeJSONLD)
w.Header().Set("X-Content-Type-Options", "nosniff") // tell clients not to infer content type from partial body

_, err := fmt.Fprintf(w, "[")
Expand Down Expand Up @@ -424,7 +417,7 @@ func (a *HTTPAPI) SearchJSONPath(w http.ResponseWriter, req *http.Request) {
}
}

w.Header().Set("Content-Type", ResponseJSONMediaType)
w.Header().Set("Content-Type", wot.MediaTypeJSON)
w.Header().Set("X-Request-URL", req.RequestURI)
_, err = w.Write(b)
if err != nil {
Expand Down Expand Up @@ -460,7 +453,7 @@ func (a *HTTPAPI) SearchXPath(w http.ResponseWriter, req *http.Request) {
}
}

w.Header().Set("Content-Type", ResponseJSONMediaType)
w.Header().Set("Content-Type", wot.MediaTypeJSON)
w.Header().Set("X-Request-URL", req.RequestURI)
_, err = w.Write(b)
if err != nil {
Expand Down Expand Up @@ -509,7 +502,7 @@ func (a *HTTPAPI) GetValidation(w http.ResponseWriter, req *http.Request) {
return
}

w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Type", wot.MediaTypeJSON)
w.WriteHeader(http.StatusOK)
_, err = w.Write(b)
if err != nil {
Expand Down

0 comments on commit d67bb61

Please sign in to comment.