Comments (7)
I resolve it
from go-restful.
I resolve it
How to solve the problem? I also encountered the same problem. thanks.
from go-restful.
I resolve it
How to solve the problem? I also encountered the same problem. thanks.
Sorry, it has been a long time, and I have already forgotten. I find some code block in my project. Maybe it's useful.
type WriterFlusher interface {
io.Writer
http.Flusher
}
// wrapperHTTP used to wrap http request for print
func wrapperHTTP(h http.Handler) http.Handler {
slogger := slog.New(slog.NewTextHandler(os.Stdout))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m := httpsnoop.CaptureMetrics(h, w, r)
defer func() {
slogger.Info("",
"method", r.Method,
"url", r.URL,
"proto", r.Proto,
"user-agent", r.UserAgent(),
"remote", r.RemoteAddr,
"referer", r.Referer(),
"status", m.Code,
"size", m.Written,
"lat-ms", m.Duration.Milliseconds(),
)
}()
})
}
func ListenAndServe(addr string, handler http.Handler) error {
return http.ListenAndServe(addr, wrapperHTTP(handler))
}
from go-restful.
I resolve it
How to solve the problem? I also encountered the same problem. thanks.
Sorry, it has been a long time, and I have already forgotten. I find some code block in my project. Maybe it's useful.
type WriterFlusher interface { io.Writer http.Flusher } // wrapperHTTP used to wrap http request for print func wrapperHTTP(h http.Handler) http.Handler { slogger := slog.New(slog.NewTextHandler(os.Stdout)) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { m := httpsnoop.CaptureMetrics(h, w, r) defer func() { slogger.Info("", "method", r.Method, "url", r.URL, "proto", r.Proto, "user-agent", r.UserAgent(), "remote", r.RemoteAddr, "referer", r.Referer(), "status", m.Code, "size", m.Written, "lat-ms", m.Duration.Milliseconds(), ) }() }) } func ListenAndServe(addr string, handler http.Handler) error { return http.ListenAndServe(addr, wrapperHTTP(handler)) }
Thanks your reply. But this does not appear to use the flush method.
from go-restful.
I suggest to figure out the actual type of ResponseWriter the server is using (using debbuger or logging). I think your ResponseWriter is not being from Go's default http package.
In this package, there is some path that it can wrap default http.ResponseWriter:
Lines 263 to 272 in c691c18
It replaces writer to CompressingResponseWriter
if something compression is needed and CompressingResponseWriter
is not implementing Flush
method for now. If your case is it, there are some options:
- disable compression
- implement
Flush
method toCompressingResponseWriter
- use
Close()
instead ofFlush()
from go-restful.
I think adding a Flush method is an easy step to take
from go-restful.
from go-restful.
Related Issues (20)
- (discussion) PrettyPrintResponses default value to false HOT 2
- Tokenizer change in 3.10 breaks many URLs HOT 33
- Security - PRISMA-2022-0227 - High Sev - emicklei/go-restful/v3 module prior to v3.10.0 is vulnerable HOT 3
- using path.Join breaks the current api HOT 6
- The go-restful-swagger12 not support go-restful version 3 HOT 4
- Whether to support a unified request results interceptors HOT 1
- which PR broke the compatible against v3.10.0 HOT 1
- Questions about WebService Path HOT 2
- Security is not exposed in RouteBuilder HOT 6
- Improper handling of empty POST requests. HOT 5
- Why were the patch versions for vulnerability (snyk id:SNYK-GOLANG-GITHUBCOMEMICKLEIGORESTFULV3-2435654) released so late? HOT 2
- default values of a slice field in a Go struct HOT 3
- Evaluation HOT 1
- List all request headers HOT 1
- unable to mock a request with selectedRoute HOT 1
- v3.11.1 checksum mismatch HOT 2
- bug: swagger type alias parse failure! HOT 1
- regex route path allows partial match HOT 5
- mis-route with multiple webservice and regex routeToken HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-restful.