HTTP

417 - Expectation Failed

Getting a 417 Expectation Failed means the server couldn't meet the requirement in your Expect header—most commonly "Expect: 100-continue" where the server refuses to send a 100 Continue response before processing the request body. This client-side error (4xx) happens when servers reject expectation headers they don't support or can't fulfill. Most common when clients send Expect: 100-continue for large uploads but the server doesn't support it, but also appears when custom expectation values are unsupported, servers explicitly reject expectations, or proxy servers strip Expect headers.

#Common Causes

  • Frontend: Sending Expect: 100-continue header but server doesn't support it. Custom Expect header values not recognized. Browser or HTTP client automatically adds Expect header. Expect header format is invalid.
  • Backend: Server doesn't implement 100-continue protocol. Expect header validation rejects the value. Server configuration disables expectation support. Proxy middleware strips Expect headers before reaching application.
  • Infrastructure: Load balancer doesn't support Expect headers. Reverse proxy strips or modifies Expect headers. API gateway rejects expectation requests. WAF blocks Expect headers for security.

Solutions

  1. 1Step 1: Diagnose - Check DevTools Network tab Request Headers—look for Expect header. Verify if Expect: 100-continue is present. Check if server response includes explanation. Review if proxy is stripping headers.
  2. 2Step 2: Diagnose - Server logs show which Expect value was rejected. Review server configuration for Expect header support. Check if middleware is removing Expect headers. Verify proxy settings.
  3. 3Step 3: Fix - Client-side: Remove Expect header if not needed (most servers work without it). Retry request without Expect header if 417 occurs. Use chunked transfer encoding instead of 100-continue.
  4. 4Step 4: Fix - Server-side: Implement 100-continue support if needed. Return 417 with clear error message. Configure middleware to pass Expect headers. Update server configuration to support expectations.
  5. 5Step 5: Fix - Infrastructure: Configure load balancer to pass Expect headers. Review reverse proxy header handling. Update API gateway to support Expect headers. Check WAF rules for Expect header blocking.

</>Code Examples

Fetch API: Handle 417 by Removing Expect Header
1// Client-side: Handle 417 by retrying without Expect header
2async function uploadData(data) {
3  // First attempt with Expect header (if needed for large uploads)
4  let response = await fetch('/api/upload', {
5  method: 'POST',
6  headers: {
7    'Content-Type': 'application/json',
8      'Expect': '100-continue', // Server may not support this
9    },
10    body: JSON.stringify(data),
11  });
12  
13  if (response.status === 417) {
14    // Server doesn't support Expect header - retry without it
15    console.warn('Server rejected Expect header, retrying without it');
16    response = await fetch('/api/upload', {
17      method: 'POST',
18      headers: {
19        'Content-Type': 'application/json',
20        // Expect header removed
21      },
22      body: JSON.stringify(data),
23    });
24  }
25  
26  return response.json();
27}
28
29// For large file uploads, use chunked encoding instead
30async function uploadLargeFile(file) {
31  // Don't use Expect: 100-continue, use chunked transfer instead
32  const formData = new FormData();
33  formData.append('file', file);
34  
35  const response = await fetch('/api/upload', {
36    method: 'POST',
37    body: formData, // FormData automatically uses chunked encoding
38    // No Expect header needed
39  });
40  
41  return response.json();
42}
Express.js: Support 100-Continue Protocol
1// Server-side: Implement 100-continue support
2const express = require('express');
3const app = express();
4
5// Middleware to handle Expect: 100-continue
6app.use((req, res, next) => {
7  const expectHeader = req.headers.expect;
8  
9  if (expectHeader && expectHeader.toLowerCase() === '100-continue') {
10    // Check if we can handle the request
11    const contentLength = parseInt(req.headers['content-length'] || '0');
12    
13    if (contentLength > 10 * 1024 * 1024) { // 10MB limit
14      // Reject with 417 if file too large
15      return res.status(417).json({
16        error: 'Expectation Failed',
17        message: 'Request body too large for 100-continue',
18      });
19    }
20    
21    // Send 100 Continue response
22    res.writeContinue();
23  }
24  
25  next();
26});
27
28// Or explicitly reject Expect headers
29app.use((req, res, next) => {
30  if (req.headers.expect && req.headers.expect.toLowerCase() === '100-continue') {
31    // Server doesn't support 100-continue
32    return res.status(417).json({
33      error: 'Expectation Failed',
34      message: '100-continue not supported',
35    });
36  }
37  next();
38});
39
40// Upload endpoint
41app.post('/api/upload', express.json({ limit: '10mb' }), (req, res) => {
42  res.json({ success: true, data: req.body });
43});
Nginx: Pass Expect Headers
1# Nginx: Configure Expect header handling
2server {
3    listen 80;
4    server_name api.example.com;
5    
6    location /api/ {
7        proxy_pass http://backend;
8        proxy_set_header Host $host;
9        proxy_set_header X-Real-IP $remote_addr;
10        
11        # Pass Expect header to backend
12        proxy_set_header Expect $http_expect;
13        
14        # Or remove Expect header if backend doesn't support it
15        # proxy_set_header Expect "";
16        
17        # Handle 100-continue
18        proxy_http_version 1.1;
19        proxy_set_header Connection "";
20    }
21}

Related Errors

Provider Information

This error code is specific to HTTP services. For more information, refer to the official HTTP documentation.

417 - Expectation Failed | HTTP Error Reference | Error Code Reference