Skip to content

proposal: net/http: add constants for mime types #48794

Closed
@Salamandastron1

Description

@Salamandastron1

[This is a template for Go's change proposal process, documented here.]

Proposal: New Constants for MIME types in net/http pkg

Author(s): Salamandastron1

Last updated: 10/5/2021

Abstract

The idea is to include these common MIME type values as constants in the net/http pkg. These values are an incredibly important part of the HTTP contract between client and server and leave a lot of room for mistakes while typing them. For ease of programming and reduced error, I believe they should be included as constants.

Background

Not much to say, Mime type values, such as JSON, HTML, Plain text, etc are common and unlikely to change. However, having to type out these values whenever needed is cumbersome and better handled as immutable values in the net/http pkg

Proposal

I propose that the various "Content-Type" options (including the key of "Content-Type") be included as constants in the net/http package. e.g.

const (
    contentHTML   =     "text/html; charset=UTF-8"
    contentPlain  =     "text/plain; charset=UTF-8"
    contentOctet  =     "application/octet-stream"
    ...
)

Rationale

The proposed change would result in ease of programming and reduced errors, for beginners and veterans alike. We are beyond the point of needing to type out these regulated values.

Trade-Offs:

  • Advantages
    • reduced errors
    • ease of programming
  • Disadvantages
    • net/http package would increase in size
    • while unlikely, changes to any of the aforementioned specifications and beyond could create toil by the need to update the constant values

Compatibility

There should be no change in compatibility

Implementation

Adding the constants into the already existing list on net/http

These changes could be deployed with any upcoming release. There are no security, reliability, or backward compatibility concerns.

Open issues (if applicable)

n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions