Code Explainers

Code explainers tagged #http-caching

go
package api
 
import (
	"crypto/sha256"

ETag conditional requests in Gin

http-caching etag conditional-requests
Intermediate 6 steps
php
<?php
 
namespace App\Http\Controllers;
 

Serving cached translations from a Laravel controller

http-caching etag localization
Intermediate 8 steps
javascript
import { NextResponse } from 'next/server';
import { readFile, stat } from 'node:fs/promises';
import { join, extname, normalize } from 'node:path';
import { createHash } from 'node:crypto';

Serving private assets from a Next.js route

path-traversal http-caching etag
Intermediate 6 steps
typescript
import {
  Controller,
  Get,
  Param,

HTTP conditional caching in a NestJS controller

http-caching etag conditional-requests
Intermediate 7 steps
java
@Configuration
public class WebConfig {
 
    @Bean

HTTP caching with ETags in Spring

http-caching etag servlet-filters
Intermediate 6 steps
rust
use axum::body::Bytes;
use axum::http::{header, HeaderValue, StatusCode};
use axum::response::{IntoResponse, Response};
use serde::Serialize;

Custom Axum responses with per-user ETags

etag trait-implementation generics
Intermediate 7 steps
javascript
const express = require('express');
const router = express.Router();
 
router.get('/articles/:slug', async (req, res, next) => {

Conditional GET caching in Express

http-caching conditional-get routing
Intermediate 8 steps
python
from pathlib import Path
 
from django.contrib.auth.decorators import login_required
from django.http import FileResponse, Http404, HttpResponseForbidden

Serving files with access checks in Django

authorization http-caching file-serving
Intermediate 7 steps
python
import hashlib
import json
from fastapi import APIRouter, Request, Response, Depends, HTTPException, status
 

HTTP ETag caching in a FastAPI route

http-caching etag conditional-requests
Intermediate 9 steps
rust
use std::time::Duration;
 
use axum::{
    http::{header, HeaderValue, Request},

Serving fingerprinted assets in Axum

static-assets http-caching middleware
Intermediate 7 steps
python
import hashlib
import os
from datetime import timedelta
 

Serving cacheable static assets in Flask

http-caching etag conditional-requests
Intermediate 8 steps
rust
use axum::{
    extract::State,
    http::{header, HeaderMap, StatusCode},
    response::{IntoResponse, Response},

Conditional GET caching in Axum

http-caching conditional-requests extractors
Intermediate 7 steps
php
<?php
 
namespace App\Http\Middleware;
 

ETag caching and gzip in Laravel middleware

middleware http-caching etag
Intermediate 8 steps
go
func GetArticle(c *gin.Context) {
	id := c.Param("id")
 
	article, err := articleRepo.FindByID(c.Request.Context(), id)

Conditional GET with ETags in Gin

http-caching etag conditional-requests
Intermediate 7 steps