-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: serve CBOR encoded DAG nodes from the gateway #8037
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,7 +529,6 @@ func (i *gatewayHandler) serveFile(w http.ResponseWriter, req *http.Request, nam | |
|
||
func (i *gatewayHandler) serveCBOR(w http.ResponseWriter, r *http.Request, n format.Node) { | ||
w.Header().Set("Cache-Control", "public, max-age=29030400, immutable") | ||
w.Header().Set("Content-Type", "application/json") | ||
maybeSetContentDispositionHeader(r.URL.Query(), w.Header()) | ||
|
||
name := r.URL.Query().Get("filename") | ||
|
@@ -538,12 +537,23 @@ func (i *gatewayHandler) serveCBOR(w http.ResponseWriter, r *http.Request, n for | |
} | ||
modtime := time.Unix(1, 0) | ||
|
||
b, err := json.Marshal(n) | ||
if err != nil { | ||
internalWebError(w, err) | ||
return | ||
var contentType string | ||
var data []byte | ||
if r.URL.Query().Get("enc") == "json" || r.Header.Get("Content-Type") == "application/json" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... oh, except "Accept" can be a comma-separated list, so the header value needs to be parsed - not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems to work pretty well:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d'oh! : forgot the label on the outer loop so the break can break all the way out. |
||
contentType = "application/json" | ||
b, err := json.Marshal(n) | ||
if err != nil { | ||
internalWebError(w, err) | ||
return | ||
} | ||
data = b | ||
} else { | ||
contentType = "application/cbor" | ||
data = n.RawData() | ||
} | ||
http.ServeContent(w, r, name, modtime, bytes.NewReader(b)) | ||
|
||
w.Header().Set("Content-Type", contentType) | ||
http.ServeContent(w, r, name, modtime, bytes.NewReader(data)) | ||
} | ||
|
||
func (i *gatewayHandler) servePretty404IfPresent(w http.ResponseWriter, r *http.Request, parsedPath ipath.Path) bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is invalid if DAG is fetched from anything other than
/ipfs/
like/ipns/
(not immutable). See gateway_handler.go#L318-L319.This may require a bigger refactor, as we want to avoid separate code paths for unixfs and cbor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.