
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
github.com/elnormous/contenttype
This library can be used to parse the value Content-Type header (if one is present) and select an acceptable media type from the Accept header of HTTP request.
Media types are stored in MediaType
structure which has Type
(e.g. application
), Subtype (e.g. json
) and Parameters (e.g. charset: utf-8
) attributes. Media types are not stored in a string because media type parameters are part of the media type (RFC 7231, 3.1.1.1. Media Type). To convert a string to MediaType
use NewMediaType
. To convert MediaType
back to string use String
function. If the Content-Type
header is not present in the request, an empty MediaType
is returned.
To get the MediaType
corresponding to the incoming request's Content-Type
header call GetMediaType
and pass the http.Request
pointer to it, or to parse any media type string call ParseMediaType
. Either function will return error if the value is malformed according to RFC 7231, 3.1.1.5. Content-Type.
To get an acceptable media type from an Accept
header of the incoming request call GetAcceptableMediaType
and pass the http.Request
pointer to it and an array of all the acceptable media types. The function will return the best match following the negotiation rules written in RFC 7231, 5.3.2. Accept or an error if the header is malformed or the content type in the Accept
header is not supported. If the Accept
header is not present in the request, the first media type from the acceptable type list is returned. If you have an Accept
header value string from a source other than req.Header.Values("Accept")
you can parse that in the same way using GetAcceptableMediaTypeFromHeader
.
import (
"log"
"github.com/elnormous/contenttype"
)
func handleRequest(responseWriter http.ResponseWriter, request *http.Request) {
mediaType, mediaTypeError := contenttype.GetMediaType(request)
if mediaTypeError != nil {
// handle the error
}
log.Println("Media type:", mediaType.String())
availableMediaTypes := []MediaType{
contenttype.NewMediaType("application/json"),
contenttype.NewMediaType("application/xml"),
}
accepted, extParameters, acceptError := contenttype.GetAcceptableMediaType(request, availableMediaTypes)
if acceptError != nil {
// handle the error
}
log.Println("Accepted media type:", accepted.String(), "extension parameters:", extParameters)
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.