Skip to content

Commit

Permalink
Revert "feat(lambda-tiler): return 204 no content instead of a empty …
Browse files Browse the repository at this point in the history
…images (#2829)" (#2836)

This reverts commit db3ff1b.

Research documentation suggest to use 200 Transparent Image.
https://github.com/linz/basemaps/blob/master/docs/api/empty-tiles.md
  • Loading branch information
Wentao-Kuang authored Jul 5, 2023
1 parent 571af3f commit f1ed481
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 26 deletions.
1 change: 0 additions & 1 deletion packages/lambda-tiler/src/__tests__/config.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const TileSetAerial: ConfigTileSetRaster = {
description: 'aerial__description',
title: 'Aerial Imagery',
category: 'Basemap',
background: { r: 0xff, g: 0x00, b: 0xff, alpha: 0.5 },
layers: [
{
2193: 'im_01FYWKAJ86W9P7RWM1VB62KD0H',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ o.spec('/v1/attribution', () => {

o('should 304 with etag match', async () => {
const request = mockUrlRequest(`/v1/attribution/aerial/EPSG:3857/summary.json`, 'get', {
[HttpHeader.IfNoneMatch]: '3un15yA8o1ZDiyYpHXwUQHYXPxd5uGtzHS3R8gug9Nn1',
[HttpHeader.IfNoneMatch]: 'E5HGpTqF8AiJ7VgGVKLehYnVfLN9jaVw8Sy6UafJRh2f',
});

const res = await handler.router.handle(request);

if (res.status === 200) o(res.header('etag')).equals('3un15yA8o1ZDiyYpHXwUQHYXPxd5uGtzHS3R8gug9Nn1');
if (res.status === 200) o(res.header('etag')).equals('E5HGpTqF8AiJ7VgGVKLehYnVfLN9jaVw8Sy6UafJRh2f');

console.log(res.header('etag'));
o(res.status).equals(304);
Expand Down
10 changes: 0 additions & 10 deletions packages/lambda-tiler/src/routes/__tests__/xyz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ o.spec('/v1/tiles', () => {
o(resB.status).equals(404);
});

o('should 204 if a tile is outside of the bounds', async () => {
const fakeTileSet = FakeData.tileSetRaster('🦄 🌈');
fakeTileSet.background = undefined;
config.put(fakeTileSet);
const res = await handler.router.handle(
mockRequest('/v1/tiles/🦄 🌈/global-mercator/0/0/0.png', 'get', Api.header),
);
o(res.status).equals(204);
});

o('should support utf8 tilesets', async () => {
const fakeTileSet = FakeData.tileSetRaster('🦄 🌈');
config.put(fakeTileSet);
Expand Down
15 changes: 2 additions & 13 deletions packages/lambda-tiler/src/routes/tile.xyz.raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pLimit from 'p-limit';
import { ConfigLoader } from '../util/config.loader.js';
import { Etag } from '../util/etag.js';
import { filterLayers } from '../util/filter.js';
import { NoContent, NotFound, NotModified } from '../util/response.js';
import { NotFound, NotModified } from '../util/response.js';
import { CoSources } from '../util/source.cache.js';
import { TileXyz } from '../util/validate.js';

Expand Down Expand Up @@ -106,25 +106,14 @@ export const TileXyzRaster = {
const tiler = new Tiler(xyz.tileMatrix);
const layers = await tiler.tile(assets, xyz.tile.x, xyz.tile.y, xyz.tile.z);

const background = tileSet.background ?? DefaultBackground;

const res = await TileComposer.compose({
layers,
format: xyz.tileType,
background,
background: tileSet.background ?? DefaultBackground,
resizeKernel: tileSet.resizeKernel ?? DefaultResizeKernel,
metrics: req.timer,
});

// If no layers are used and the tile is going to be transparent
// return 204 no content instead of a empty image
if (res.layers === 0 && background.alpha === 0) {
const response = NoContent();
response.header(HttpHeader.ETag, cacheKey);
response.header(HttpHeader.CacheControl, 'public, max-age=604800, stale-while-revalidate=86400');
return response;
}

req.set('layersUsed', res.layers);
req.set('bytes', res.buffer.byteLength);

Expand Down

0 comments on commit f1ed481

Please sign in to comment.