Skip to content

cvam29/ResponseCompressionPOC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Azure Functions In-Proc Response Compression (POC)

This repository contains a proof of concept (POC) demonstrating how to implement response compression (Gzip and Brotli) in Azure Functions (In-Process model). It enables HTTP-triggered functions to return compressed responses based on the Accept-Encoding header.


πŸ“Œ Purpose

Optimize Azure Function responses by reducing payload sizes, improving transfer speeds, and supporting clients with modern compression algorithms.


✨ Features

  • βœ… In-process Azure Functions using .NET 8
  • βœ… Supports Gzip and Brotli compression
  • βœ… Detects Accept-Encoding from incoming requests
  • βœ… Applies dynamic compression on JSON/text payloads
  • βœ… Uses Newtonsoft.Json for serialization
  • βœ… Lightweight and extensible structure

🧱 Project Structure


ResponseCompression/
β”œβ”€β”€ Properties/
β”‚   β”œβ”€β”€ launchSettings.json
β”‚   └── serviceDependencies.json
β”œβ”€β”€ Extensions/
β”‚   └── AzureFunctionsInProcessCompressionExtensions.cs
β”œβ”€β”€ Functions/
β”‚   └── CompressedJsonFunction.cs
β”œβ”€β”€ GlobalUsings.cs
β”œβ”€β”€ host.json
β”œβ”€β”€ local.settings.json
β”œβ”€β”€ .gitignore
└── README.md


πŸ—οΈ Tech Stack

  • Azure Functions (In-Proc)
  • .NET 8
  • System.IO.Compression
  • Newtonsoft.Json

πŸš€ Running Locally

πŸ”§ Prerequisites

▢️ Start the Function App

func start

By default, the function runs on:

http://localhost:7169

πŸ“€ Example Usage with curl

πŸ—œοΈ Gzip

curl -H "Accept-Encoding: gzip" http://localhost:7169/api/compressed-json --output response.gz

πŸ—œοΈ Brotli

curl -H "Accept-Encoding: br" http://localhost:7169/api/compressed-json --output response.br

🧾 No Compression

curl http://localhost:7169/api/compressed-json

🧠 How It Works

  1. CompressedJsonFunction receives the HTTP request
  2. Reads the Accept-Encoding header
  3. Serializes the response using Newtonsoft.Json
  4. Applies compression (Gzip or Brotli) using System.IO.Compression
  5. Sets appropriate Content-Encoding and Content-Type headers
  6. Returns the compressed stream as the response

➑️ Compression logic is encapsulated in:
Extensions/AzureFunctionsInProcessCompressionExtensions.cs


πŸ“š References


❗ Limitations

  • Designed for the in-process model only
  • Not suitable for binary or large media content
  • ASP.NET Core middleware pipeline is not available in in-proc model

πŸ™Œ Contributions

Feel free to fork, extend, and improve this POC. Pull requests are welcome!

About

πŸ“¦ Azure Functions In-Proc Response Compression (POC) This proof of concept demonstrates how to implement response compression (Gzip and Brotli) in Azure Functions (In-Process model). The goal is to reduce payload sizes for HTTP-triggered Azure Functions by applying content encoding based on the client's Accept-Encoding header.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages