rfc7231

package
v0.0.0-...-00f1f15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2015 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Middleware = he.Middleware{
	Inside: func(request he.Request, entity he.Entity, handle func(he.Request, he.Entity) he.Response) (response he.Response) {
		switch request.Method {
		case "OPTIONS":
			response := handle(request, entity)
			if response.Status == 405 {
				methods := entity.Methods()
				response.Headers.Set("Allow", methods2string(methods))
			}
			response.Status = 204
			response.Entity = nil

		case "HEAD":
			request.Method = "GET"
			response := handle(request, entity)
			response.Entity = nil
		default:
			response = handle(request, entity)
		}
		if response.Status == 405 {
			methods := entity.Methods()
			response.Headers.Set("Allow", methods2string(methods))
		}

		if l := response.Headers.Get("Location"); l != "" {
			u2, _ := request.URL.Parse(l)
			response.Headers.Set("Location", u2.String())
		}

		return
	},
}

Middleware is a good default middleware for httpentity that provides much of the boilerplate for RFC 7231 semantics.

Functions

func StatusAccepted

func StatusAccepted(e he.NetEntity) he.Response

For when you've received a request, but haven't completed it yet (ex, it has been added to a queue).

func StatusBadRequest

func StatusBadRequest(e he.NetEntity) he.Response

For when the *user* has screwed up a request.

func StatusConflict

func StatusConflict(entity he.NetEntity) he.Response

For when the user asked us to make a change conflicting with the current state of things.

func StatusCreated

func StatusCreated(parent he.EntityGroup, childName string, req he.Request) he.Response

For when you've created a document with a new URL.

func StatusForbidden

func StatusForbidden(e he.NetEntity) he.Response

func StatusFound

func StatusFound(u *url.URL) he.Response

For when the document the user requested is currently found at another address, but that may not be the case in the future.

The client may change a POST to a GET request when trying the new location.

func StatusGone

func StatusGone(entity he.NetEntity) he.Response

For the resource has been deleted, and will never ever return.

func StatusInternalServerError

func StatusInternalServerError(err interface{}) he.Response

func StatusMethodNotAllowed

func StatusMethodNotAllowed(entity he.Entity, request he.Request) he.Response

func StatusMovedPermanently

func StatusMovedPermanently(u *url.URL) he.Response

For when the document the user requested has permantly moved to a new address.

func StatusMultipleChoices

func StatusMultipleChoices(u *url.URL, mimetypes []string) he.Response

For when you have document in multiple formats, but you're not sure which the user wants.

func StatusNoContent

func StatusNoContent() he.Response

For when you've successfully done something, but have no body to return.

func StatusNotAcceptable

func StatusNotAcceptable(u *url.URL, mimetypes []string) he.Response

func StatusNotFound

func StatusNotFound(e he.NetEntity) he.Response

func StatusNotImplemented

func StatusNotImplemented(e he.NetEntity) he.Response

func StatusOK

func StatusOK(entity he.NetEntity) he.Response

For when you're returning a document, with nothing special.

func StatusResetContent

func StatusResetContent() he.Response

The client should reset the form of whatever view it currently has.

func StatusSeeOther

func StatusSeeOther(u *url.URL) he.Response

func StatusTemporaryRedirect

func StatusTemporaryRedirect(u *url.URL) he.Response

For when rhe document the user requested has temporarily moved.

The client must repeate the request exactly the same, except for the URL.

func StatusUnsupportedMediaType

func StatusUnsupportedMediaType(e he.NetEntity) he.Response

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL