英文:
set the Access-Control-Allow-Credentials Header in Response
问题
我想在go-endpoints中使用Cookie。
为了实现这个目的,需要将Access-Control-Allow-Credentials设置为Header。
然而,我不知道如何在go-endpoints中设置Allow-Credentials为Header。
allowCookieAuth是什么?如何将其设置为true?
由于go-endpoints处理程序中没有http.ResponseWriter,所以无法设置Http Header。
请帮助我!
英文:
I want to use Cookie along with the go-endpoints.
For this purpose , it is necessary to set the Access-Control-Allow-Credentials to Header.
However , do not know how to set the Allow-Credentials to Header in go-endpoints.
allowCookieAuth is , How do I to true doing ?
https://github.com/GoogleCloudPlatform/go-endpoints/search?utf8=%E2%9C%93&q=allowCookieAuth
because there is no http.ResponseWriter the go-endpoints handler , it is not possible to set the Http Header.
func (gs *GreetingService) List(c endpoints.Context, r *GreetingsListReq) (*GreetingsList, error) {
if r.Limit <= 0 {
r.Limit = 10
}
q := datastore.NewQuery("Greeting").Limit(r.Limit)
greets := make([]*Greeting, 0, r.Limit)
keys, err := q.GetAll(c, &greets)
if err != nil {
return nil, err
}
for i, k := range keys {
greets[i].Key = k
}
return &GreetingsList{greets}, nil
}
help me!
答案1
得分: 1
如果我理解你的意思正确,那么你只需要像下面这样做:
func yourHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Credentials", "true")
// ...其他代码
}
英文:
If I understand you correctly then all you have to do is something like:
func yourHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Credentials", "true")
// ...other code
}
答案2
得分: 0
通过修补go-endpoints,并达到目标。
dst.Auth = &struct {
AllowCookie bool json:"allowCookieAuth"
}{true}
https://github.com/sinmetal/go-endpoints/commit/25c0e85b06c13511291cb8b54f2878c5ac4587ad
然而,我认为这不是一个很好的方法。
如果可能的话,我希望在不进行修补的情况下达到目标。
英文:
By patching the go-endpoints, and reached the goal .
dst.Auth = &struct {
AllowCookie bool `json:"allowCookieAuth"`
}{true}
https://github.com/sinmetal/go-endpoints/commit/25c0e85b06c13511291cb8b54f2878c5ac4587ad
However , I do not think that's very good way .
If possible , I want to reach the goal without patching .
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论