Skip to content

Add AVIF image endpoint support #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArnavBallinCode
Copy link

@ArnavBallinCode ArnavBallinCode commented May 2, 2025

Fix for Issue #54

Overview

Added a new endpoint /image/avif to serve images in AVIF format, expanding httpbin's image format support alongside existing PNG, JPEG, and WebP endpoints.

Environment Details

  • httpbin version: 0.10.2 (installed via direct repository clone)
  • Python version: 3.10
  • OS: macOS 13.4
  • Dependencies:
    • System: libavif 0.11.1
    • Python packages: See requirements.txt

Expected Behavior

  1. Endpoint Response:

    • Status code: 200 OK
    • Content-Type: image/avif
    • Valid AVIF image data returned
  2. Browser Behavior:

    • Image displays correctly in AVIF-supporting browsers
    • Proper content type headers received
  3. Docker Container:

    • Successfully builds and runs
    • Serves AVIF images correctly
    • Maintains all existing functionality

Actual Results

All expected behaviors have been verified:

  1. Endpoint Testing (screenshots attached):

    HTTP/1.1 200 OK
    Content-Type: image/avif
    Content-Length: [size]
    
  2. Browser Testing (screenshots attached):

    • Successfully displays in Chrome and Firefox
    • Network tab shows correct headers
    • Image loads properly
  3. Docker Testing (screenshots attached):

    • Container builds successfully
    • Endpoint accessible and functioning
    • All tests passing

Implementation Details

  1. New Code:
@app.route("/image/avif")
def image_avif():
    """Returns a simple AVIF image.
    ---
    tags:
      - Images
    produces:
      - image/avif
    responses:
      200:
        description: An AVIF image.
    """
    data = resource("images/pig_icon.avif")
    return Response(data, headers={"Content-Type": "image/avif"})
  1. Files Modified:
    • core.py: Added new endpoint
    • images/: Added AVIF version of pig icon
    • requirements.txt: Added AVIF dependencies
    • Dockerfile: Added system dependencies

Testing Verification

  1. Local Testing:
# Endpoint test
curl -I http://localhost:8000/image/avif
curl -v http://localhost:8000/image/avif > test.avif

# Image format verification
file httpbin/templates/images/pig_icon.avif
  1. Docker Testing:
docker build -t httpbin:avif .
docker run -d -p 8080:8080 httpbin:avif
curl -I http://localhost:8080/image/avif

Backwards Compatibility

  • No existing endpoints modified
  • No changes to current functionality
  • Only adds new capability
  • Maintains existing image format support

Additional Notes

  • All test cases documented with screenshots
  • No exceptions or errors encountered during testing
  • Implementation follows existing pattern of image endpoints
  • Docker build and deployment verified
  • Browser compatibility confirmed

Attachments

  • Screenshot: Curl response headers
  • Screenshot: Browser rendering
  • Screenshot: Docker container tests
Screenshot 2025-05-02 at 7 34 43 PM Screenshot 2025-05-02 at 7 35 01 PM Screenshot 2025-05-02 at 7 35 08 PM

This PR has been thoroughly tested and documented according to the project's contribution guidelines. All test cases are reproducible using the provided instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant