fasthttpadaptor

package
v1.11.2-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

fasthttpadaptor

This package contains a fork of https://github.com/valyala/fasthttp/tree/v1.41.0/fasthttpadaptor with some Dapr-specific changes.

These changes are only needed to support the hybrid state in which Dapr's HTTP server is using fasthttp, and the HTTP channel (and its middlewares) are using net/http. This package will be obsolete when #4979 is addressed.

License

The MIT License (MIT)

Copyright (c) 2015-present Aliaksandr Valialkin, VertaMedia, Kirill Danshin, Erik Dubbelboer, FastHTTP Authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package fasthttpadaptor provides helper functions for converting net/http request handlers to fasthttp request handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertRequest

func ConvertRequest(ctx *fasthttp.RequestCtx, r *http.Request, forServer bool) error

ConvertRequest converts a fasthttp.Request to an http.Request. forServer should be set to true when the http.Request is going to passed to a http.Handler.

The http.Request must not be used after the fasthttp handler has returned! Memory in use by the http.Request will be reused after your handler has returned!

func NewFastHTTPHandler

func NewFastHTTPHandler(h http.Handler) fasthttp.RequestHandler

NewFastHTTPHandler wraps net/http handler to fasthttp request handler, so it can be passed to fasthttp server.

While this function may be used for easy switching from net/http to fasthttp, it has the following drawbacks comparing to using manually written fasthttp request handler:

  • A lot of useful functionality provided by fasthttp is missing from net/http handler.
  • net/http -> fasthttp handler conversion has some overhead, so the returned handler will be always slower than manually written fasthttp handler.

So it is advisable using this function only for quick net/http -> fasthttp switching. Then manually convert net/http handlers to fasthttp handlers according to https://github.com/valyala/fasthttp#switching-from-nethttp-to-fasthttp .

func NewFastHTTPHandlerFunc

func NewFastHTTPHandlerFunc(h http.HandlerFunc) fasthttp.RequestHandler

NewFastHTTPHandlerFunc wraps net/http handler func to fasthttp request handler, so it can be passed to fasthttp server.

While this function may be used for easy switching from net/http to fasthttp, it has the following drawbacks comparing to using manually written fasthttp request handler:

  • A lot of useful functionality provided by fasthttp is missing from net/http handler.
  • net/http -> fasthttp handler conversion has some overhead, so the returned handler will be always slower than manually written fasthttp handler.

So it is advisable using this function only for quick net/http -> fasthttp switching. Then manually convert net/http handlers to fasthttp handlers according to https://github.com/valyala/fasthttp#switching-from-nethttp-to-fasthttp .

Types

type NetHTTPResponseWriter

type NetHTTPResponseWriter struct {
	// contains filtered or unexported fields
}

func (*NetHTTPResponseWriter) Flush added in v1.10.5

func (w *NetHTTPResponseWriter) Flush()

func (*NetHTTPResponseWriter) Header

func (w *NetHTTPResponseWriter) Header() http.Header

func (*NetHTTPResponseWriter) SetUserValue

func (w *NetHTTPResponseWriter) SetUserValue(key any, value any)

func (*NetHTTPResponseWriter) StatusCode

func (w *NetHTTPResponseWriter) StatusCode() int

func (*NetHTTPResponseWriter) Write

func (w *NetHTTPResponseWriter) Write(p []byte) (int, error)

func (*NetHTTPResponseWriter) WriteHeader

func (w *NetHTTPResponseWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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