summaryrefslogtreecommitdiff
path: root/desk/ted/fetch.hoon
blob: 6444ca788d80d4b7a9af1ddbf641be85ae7756db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/-  spider
/+  strandio
=,  strand=strand:spider
=,  dejs-soft:format
=,  strand-fail=strand-fail:libstrand:spider
^-  thread:spider
|=  arg=vase
  =/  request  ;;(request:http q.arg) 
  ~&  req=request
  =/  m  (strand ,vase)  ^-  form:m
  :: =/  m  (strand ,json)  ^-  form:m
  ;<  ~  bind:m  (send-request:strandio request)
  ;<  res=client-response:iris  bind:m  take-client-response:strandio
  ?.  ?=(%finished -.res)  (strand-fail:strand %no-body ~)
  :: =/  headers  headers.response-header.res  
  :: =/  redirect  (get-header:http 'location' headers)
  ::   ?^  redirect  (pure:m [%| u.redirect])  

  ::
  ?~  full-file.res  (strand-fail:strand %no-body ~)
  =/  body=@t  q.data.u.full-file.res
  :: ~&  resbody=body
  =/  json  [%s body]
  (pure:m !>(json))