https://github.com/nir3x/httpcontentwriter
HTTP Content Writer - Custom http.ResponseWriter for Dynamic Content-Type
https://github.com/nir3x/httpcontentwriter
content-type go golang http http-response middleware
Last synced: 3 months ago
JSON representation
HTTP Content Writer - Custom http.ResponseWriter for Dynamic Content-Type
- Host: GitHub
- URL: https://github.com/nir3x/httpcontentwriter
- Owner: NIR3X
- License: agpl-3.0
- Created: 2024-02-01T04:33:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-16T04:03:36.000Z (over 1 year ago)
- Last Synced: 2024-06-21T15:37:13.840Z (11 months ago)
- Topics: content-type, go, golang, http, http-response, middleware
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP Content Writer - Custom http.ResponseWriter for Dynamic Content-Type
The `httpcontentwriter` package provides a custom `http.ResponseWriter` implementation that allows you to set the content type on the first write. This can be useful in scenarios where you want to dynamically determine the content type based on the content being written.
## Installation
You can install the package using the `go get` command:
```bash
go get -u github.com/NIR3X/httpcontentwriter
```## Usage
```go
package mainimport (
"net/http"
"github.com/NIR3X/httpcontentwriter"
)func handler(w http.ResponseWriter, r *http.Request) {
// Create a new HttpContentWriter instance
contentWriter := httpcontentwriter.NewHttpContentWriter(w)// Your logic here, writing content to the response using contentWriter
contentWriter.Write([]uint8("Hello, World!"))
}func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
```## License
[](https://www.gnu.org/licenses/agpl-3.0.html)
This program is Free Software: You can use, study share and improve it at your
will. Specifically you can redistribute and/or modify it under the terms of the
[GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) as
published by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.