HTTP 305 Use Proxy

Overview

The HTTP 305 Use Proxy status code indicates that the requested resource is only accessible through the proxy identified by the Location field in the response.

Purpose

The HTTP 305 response directs the client to use a specified proxy to access the requested resource. This status code is defined for future use and is not commonly used in modern web applications.

Usage

Client Behavior:

  1. Send Request: The client sends an HTTP request to a resource’s URI.
  2. Receive Response: The client receives the HTTP 305 status code with the URI of the proxy in the Location header.

Server Behavior:

  1. Redirect to Proxy: The server determines that the requested resource must be accessed through a proxy.
  2. Send Response: The server sends a 305 Use Proxy response, indicating the URI of the proxy in the Location header.

Scenarios

  • Proxy Redirection: Used to inform the client that a specific proxy must be used to access the requested resource.
  • Rarely Used: This status code is seldom used in practice and is mostly reserved for future use.

Sequence Diagram

Illustrating the process for an HTTP 305 response:

sequenceDiagram
    participant Client
    participant Server as Web Server

    Note over Client: Client requests a resource
    Client->>Server: GET /resource HTTP/1.1
    Note over Server: Server requires proxy access
    Server->>Client: HTTP/1.1 305 Use Proxy
    Server->>Client: Location: http://proxy.example.com

Curl Request and Response Example

Sending a request using Curl to a resource that might redirect to a proxy:

curl -i http://example.com/resource
# Expected response: HTTP/1.1 305 Use Proxy
# Location: http://proxy.example.com

PHP cURL Request and Response Example

PHP script using cURL to handle a request that might result in a 305 Use Proxy response:

<?php
$ch = curl_init('http://example.com/resource');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 305) {
    $proxyUrl = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
    echo "Access the resource through proxy at: " . $proxyUrl;
}
curl_close($ch);
?>

Python Request and Response Example

Python script to send a GET request and handle a 305 Use Proxy response:

import requests
response = requests.get('http://example.com/resource')
if response.status_code == 305:
    print("Access the resource through proxy at:", response.headers['Location'])

Apache Configuration for HTTP 305 Use Proxy

Apache server configuration to redirect requests to a proxy (Note: 305 Use Proxy is rarely used):

<VirtualHost *:80>
    ServerName example.com
    # Configuration directives for 305 Use Proxy
    # ...
</VirtualHost>

NGINX Configuration for HTTP 305 Use Proxy

Setting up NGINX to handle HTTP 305 Use Proxy responses (Note: 305 Use Proxy is rarely used):

server {
    listen 80;
    server_name example.com;
    location /resource {
        # Configurations for issuing a 305 Use Proxy response
        # ...
    }
}

HTTP 304 Not Modified HTTP 306 (Unused)


 

Free Weekly

Newsletter

Join my weekly newsletter for the latest in tech! You'll get neat coding tricks, trend updates, career advice, SaaS reviews, crypto, bitcoin, and financial tips. All straight to your inbox, designed to keep you ahead.