Code Explainers

Code explainers tagged #http-headers

java
@RestController
@RequestMapping("/api/reports")
public class OrderReportController {
 

Streaming a CSV export in Spring

streaming csv-export backpressure
Intermediate 9 steps
python
import time
 
from flask import Flask, g, request
 

Timing requests with Flask hooks

middleware request-lifecycle instrumentation
Intermediate 5 steps
go
func ProxyDownload(c *gin.Context) {
	objectKey := c.Param("key")
	upstream := fmt.Sprintf("%s/files/%s", storageBaseURL, objectKey)
 

Streaming a proxied download in Gin

reverse-proxy streaming http-headers
Intermediate 8 steps
rust
use std::time::Duration;
 
use axum::{
    extract::State,

Rate-limit errors as Axum responses

error-handling rate-limiting http-headers
Intermediate 6 steps
go
package server
 
import (
	"net/http"

Serving cached static assets in Gin

caching static-files middleware
Intermediate 7 steps
go
package middleware
 
import (
	"net/http"

Building a CORS middleware in Gin

cors middleware closures
Intermediate 9 steps
typescript
import { Controller, Get, Param, StreamableFile, Res, NotFoundException, Header } from '@nestjs/common';
import { Response } from 'express';
import { createReadStream, promises as fsp } from 'fs';
import { join } from 'path';

Streaming CSV file downloads in NestJS

file-streaming http-headers error-handling
Intermediate 7 steps
rust
use axum::{
    extract::{Path, State},
    http::{header, HeaderMap, StatusCode},
    response::{IntoResponse, Response},

Optimistic concurrency with ETags in Axum

optimistic-concurrency etag http-headers
Intermediate 8 steps
javascript
import { NextResponse } from 'next/server'
 
const UPSTREAM = 'https://api.exchangerate.host/latest'
 

A cached exchange-rate proxy in Next.js

route-handler caching revalidation
Intermediate 7 steps
rust
use axum::{
    extract::Path,
    http::{header::ACCEPT, HeaderMap, StatusCode},
    response::{Html, IntoResponse, Json, Response},

Content negotiation in an Axum handler

content-negotiation http-headers serialization
Intermediate 8 steps
javascript
const crypto = require('crypto');
 
function securityHeaders(options = {}) {
  const {

A configurable security-headers middleware in Express

middleware http-headers content-security-policy
Intermediate 7 steps
rust
use std::time::Duration;
 
use axum::{
    http::{header, HeaderValue, Method},

Configuring CORS on an Axum Router

cors middleware http-headers
Intermediate 7 steps
javascript
const RATE_LIMIT = 100;
const WINDOW_MS = 60 * 1000;
const BLOCK_MS = 5 * 60 * 1000;
 

Building a rate-limiting middleware in Express

rate-limiting middleware closures
Intermediate 9 steps
rust
use axum::{
    body::Body,
    extract::Request,
    http::{header::HeaderValue, HeaderName},

Request ID middleware in Axum

middleware tracing request-extensions
Intermediate 7 steps
php
<?php
 
namespace App\Http\Middleware;
 

Enforcing a JSON Accept header in Laravel

middleware content-negotiation http-headers
Beginner 5 steps
rust
use axum::{
    body::Body,
    extract::Path,
    http::{header, StatusCode},

Streaming file downloads in Axum

streaming file-serving path-traversal
Intermediate 8 steps