Skip to content

add header in http.Handler,but not take effect #1835

Closed
@damozhiying

Description

@damozhiying

grpc-gateway rest server

srv := &http.Server{
		Addr:         httpPort,
		ReadTimeout:  60 * time.Second,
		WriteTimeout: 60 * time.Second,
		// add handler with middleware
		Handler: middleware.AddRequestID(
			middleware.AddLogger(log.WithField("gateway", "rest"), handler)),
	}

AddLogger code

func AddLogger(logger *logrus.Entry, h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

h.ServeHTTP(w, r)

w.Header().Set("Grpc-Metadata-Yyyyyyyyyyyyyyyy-Request-ID", "fadfadsfadsf")
		w.Header()["TEST-HEADER-EKY"] = []string{"TEST-HEADER-EKY-110"}
		hs["TEST-HEADER-EKY-1"] = []string{"TEST-HEADER-EKY-110-1"}
		w.Header().Set("Access-Control-Allow-Origin", "*")

browser f12 show

Content-Type →application/json
Lxf--Abc-Www-Authenticate →222222222xxxxxxxxxx
Lxf--Content-Type →application/grpc
Lxf--Grpc-Metadata-Some-Key →222222222xxxxxxxxxx
Lxf--Www-Authenticate →222222222xxxxxxxxxx
Date →Mon, 23 Nov 2020 01:18:04 GMT
Content-Length →120

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions