Beispiel #1
0
func downloadHeaders(ctx context.Context, hq *headerQueue, finished chan<- *headerQueue) {
	vhost, ok := contexts.GetVhost(ctx)
	if !ok {
		hq.err = fmt.Errorf("Could not get vhost from context.")
		finished <- hq
		return
	}

	resp, err := vhost.Upstream.GetHeader(hq.id.Path)
	if err != nil {
		hq.err = err
	} else {
		hq.header = resp.Header
		//!TODO: handle allowed cache duration
		hq.isCacheable, _ = utils.IsResponseCacheable(resp)
	}

	finished <- hq
}
Beispiel #2
0
func (s *Disk) startDownloadIndex(request *indexRequest) *indexDownload {
	download := &indexDownload{
		index:    request.index,
		requests: []*indexRequest{request},
	}
	go func(ctx context.Context, download *indexDownload, index types.ObjectIndex) {
		file, resp, err := s.downloadIndex(ctx, index)
		if err != nil {
			download.err = err
		} else {
			download.file = file
			//!TODO: handle allowed cache duration
			download.isCacheable, _ = utils.IsResponseCacheable(resp)
			if download.isCacheable {
				s.writeObjectIDIfMissing(download.index.ObjID)
				//!TODO: don't do it for each piece and sanitize the headers
				s.writeHeaderToFile(download.index.ObjID, resp.Header)
			}
		}
		s.downloaded <- download
	}(request.context, download, request.index)
	return download
}