summaryrefslogtreecommitdiff
path: root/src/scm/webid-oidc/fetch.scm
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2021-07-27 10:59:45 +0200
committerVivien Kraus <vivien@planete-kraus.eu>2021-07-27 13:40:09 +0200
commite150c1b232294d9352b61df22e82e2d4513b615e (patch)
tree22ab5b13caed5c5ec942fde2e13c475e19b97e9b /src/scm/webid-oidc/fetch.scm
parent4d9a10165a6c7bf8df6f86f032bf7b3412e83ae6 (diff)
Support for json-ld
Diffstat (limited to 'src/scm/webid-oidc/fetch.scm')
-rw-r--r--src/scm/webid-oidc/fetch.scm45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/scm/webid-oidc/fetch.scm b/src/scm/webid-oidc/fetch.scm
index f998ba2..c027787 100644
--- a/src/scm/webid-oidc/fetch.scm
+++ b/src/scm/webid-oidc/fetch.scm
@@ -23,7 +23,11 @@
#:use-module (web request)
#:use-module (web response)
#:use-module (web uri)
- #:use-module (turtle tordf))
+ #:use-module (rdf rdf)
+ #:use-module (turtle tordf)
+ #:use-module (nquads tordf)
+ #:use-module (json)
+ #:use-module (jsonld))
(define*-public (fetch uri #:key (http-get http-get))
(unless (uri? uri)
@@ -34,7 +38,7 @@
(lambda ()
(receive (response response-body)
(http-get uri
- #:headers `((accept (text/turtle))))
+ #:headers `((accept (text/turtle application/n-quads application/ld+json))))
(with-exception-handler
(lambda (error)
(raise-unexpected-response response error))
@@ -44,17 +48,30 @@
(response-reason-phrase response)))
(let ((content-type (response-content-type response)))
(unless (and content-type
- (eq? (car content-type) 'text/turtle)
+ (or
+ (eq? (car content-type) 'text/turtle)
+ (eq? (car content-type) 'application/n-quads)
+ (eq? (car content-type) 'text/x-nquads)
+ (eq? (car content-type) 'application/ld+json))
(or (not (assq-ref (cdr content-type) 'charset))
(equal? (assq-ref (cdr content-type) 'charset) "utf-8")))
- (raise-unexpected-header-value 'content-type content-type)))
- (when (bytevector? response-body)
- (set! response-body (utf8->string response-body)))
- (with-exception-handler
- (lambda (rdf-error)
- (raise-not-turtle response-body rdf-error))
- (lambda ()
- (turtle->rdf (string-append
- "# This is not a file name\n"
- response-body)
- (uri->string uri))))))))))
+ (raise-unexpected-header-value 'content-type content-type))
+ (when (bytevector? response-body)
+ (set! response-body (utf8->string response-body)))
+ (with-exception-handler
+ (lambda (rdf-error)
+ (raise-not-turtle response-body rdf-error))
+ (lambda ()
+ (case (car content-type)
+ ((text/turtle)
+ (turtle->rdf (string-append
+ "# This is not a file name\n"
+ response-body)
+ (uri->string uri)))
+ ((application/ld+json)
+ (rdf-dataset-default-graph
+ (jsonld->rdf (json-string->scm response-body))))
+ ((application/n-quads text/x-nquads)
+ (nquads->rdf (string-append
+ "# This is not a file name\n"
+ response-body)))))))))))))