• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Klowner / tussle / 8ee34bb7-b502-4225-abb7-e1291f281f8e

pending completion
8ee34bb7-b502-4225-abb7-e1291f281f8e

push

circleci

Mark Riedesel
bump lerna to ^6.4.1

218 of 549 branches covered (39.71%)

Branch coverage included in aggregate %.

903 of 1504 relevant lines covered (60.04%)

16.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.13
/packages/core/src/handlers/head.ts
1
import { Observable, of, from as observableFrom } from "rxjs";
1✔
2
import type { TussleIncomingRequest } from '@tussle/spec/interface/request';
3
import type { TussleStorageFileInfo } from '@tussle/spec/interface/storage';
4
import type { Tussle } from '../core';
5
import { switchMap, map } from 'rxjs/operators';
1✔
6

7
export default function handleHead<Req, P>(
1✔
8
  _core: Tussle,
9
  ctx: TussleIncomingRequest<Req, P>
10
): Observable<TussleIncomingRequest<Req, P>>
11
{
12
  const params = extractParamsFromHeaders(ctx);
×
13
  const store = ctx.cfg.storage;
×
14
  if (!store) {
×
15
    return of(toResponse(ctx, {location: ctx.request.path, info: null}));
×
16
  } else {
17
    const params$ = observableFrom(ctx.source.hook('before-head', ctx, params));
×
18
    return params$.pipe(
×
19
      switchMap((params) => store.getFileInfo(params)),
×
20
      switchMap((params) => ctx.source.hook('after-head', ctx, params)),
×
21
      map(fileInfo => toResponse(ctx, fileInfo)),
×
22
    );
23
  }
24
}
25

26
const extractParamsFromHeaders = <T, P>(ctx: TussleIncomingRequest<T, P>) => {
1✔
27
  const location = ctx.request.path;
×
28
  return {
×
29
    location,
30
  };
31
};
32

33
export type ExtractedHeadHeaders = ReturnType<typeof extractParamsFromHeaders>;
34

35
const toResponse = <T, P>(
1✔
36
  ctx: TussleIncomingRequest<T, P>,
37
  fileInfo: TussleStorageFileInfo,
38
): TussleIncomingRequest<T, P> => {
39
  const { info } = fileInfo;
×
40
  if (info) {
×
41
    const headers: Record<string, string> = {
×
42
      'Upload-Offset': (info.currentOffset || 0).toString(),
×
43
    };
44
    if (typeof info.uploadLength === 'number') {
×
45
      headers['Upload-Length'] = info.uploadLength.toString();
×
46
    }
47
    ctx.response = {
×
48
      status: 200, // OK
49
      headers,
50
    };
51
  } else {
52
    ctx.response = {
×
53
      status: 410, // GONE
54
    };
55
  }
56
  return ctx;
×
57
};
58

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc