Firebase功能不会返回set-cookies标头

时间:2017-08-20 13:23:05

标签: javascript firebase google-cloud-functions firebase-hosting

我想知道为什么在firebase函数中设置set-cookie标头时,在使用firebase工具模拟器时它不会显示在浏览器的响应头上。

function TForm2.CreateOrUpdate(username: String; NewTimestamp: TDateTime): String;
var
  poiTimeStamp: TDateTime;
  myPOI: TMyPOI;
  Index: Integer;
begin

  if PoiDict.TryGetValue(username, myPOI) then
  begin
    // existing POI
    Result := InttoStr(myPOI.Value) + ' ' + DateTimeToStr(myPoi.Timestamp);
    poiTimestamp := myPOI.Timestamp;
    // update the Poi's timestamp - this will update object in dictionary 
    myPOI.Timestamp := NewTimeStamp;
  end
  else
  begin
    // add a new POI
    Index := Random(999);
    Result := IntToStr(Index) + ' ' + DateTimeToStr(NewTimeStamp);
    myPOI := TMyPOI.Create;
    try
      myPOI.Value := Index;
      myPOI.Timestamp := NewTimeStamp;
      PoiDict.Add(username, myPOI);
    except
      myPOI.Free;
      raise;
    end;
  end;

end;

initialization
  PoiDict := TObjectDictionary<string, TMyPOI>.Create([doOwnsValues]);

finalization
  PoiDict.Free;

end.

2 个答案:

答案 0 :(得分:1)

此功能是独立功能还是您将其与Firebase Hosting集成?我尝试了以下功能:

exports.headers = functions.https.onRequest((req, res) => {
  res.setHeader('X-Test', 'OK');
  res.setHeader('Set-Cookie', ['__session=ninja'])
  res.send('OK');
});

我在响应中看到了x和set-cookie标头。

答案 1 :(得分:0)

此外,您需要将Cache-control设置为private:

res.setHeader('Cache-Control', 'private');