Skip to content

Expose HTTP headers in CloudEvent Signature #34

@grant

Description

@grant

GCF event requests send information in the HTTP headers that we currently don't expose to the user.

Example HTTP headers seen from a GCF V1 Pub/Sub event (here, represented as an object):

{
        "host": "2103cfee64826ae687aca0732ae6f7fd-dot-ucd5d3fce07973027-tp.appspot.com",
        "user-agent": "CloudPubSub-Google",
        "content-length": "392",
        "accept-charset": "UTF-8",
        "content-type": "application/json",
        "forwarded": "for=\"2002:a30:591a:0:b029:f3:1843:9b30\";proto=https",
        "function-execution-id": "bxb97ephkgb0",
        "traceparent": "00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01",
        "x-appengine-country": "ZZ",
        "x-appengine-default-version-hostname": "ucd5d3fce07973g27-tp.appspot.com",
        "x-appengine-https": "on",
        "x-appengine-request-log-id": "5f50211300ff05432dbed9b52a0001737e75636435643366636530343937333032372d7470000132313033636665653634383236326536383761636130373332616536663766643a3100010102",
        "x-appengine-timeout-ms": "599999",
        "x-appengine-user-ip": "2002:a30:591a:0:b029:f3:1843:9b30",
        "x-cloud-trace-context": "65088637f09e0a5159677a7429456db7/10948871334010811884;o=1",
        "x-forwarded-for": "2002:a30:591a:0:b029:f3:1843:9b30",
        "x-forwarded-proto": "https",
        "x-google-internal-skipadmincheck": "true",
        "connection": "close"
}

V2:

{
  "host": "headers-v2-qqawgke5q-uw.a.run.app",
  "user-agent": "curl/7.64.1",
  "accept": "*/*",
  "x-cloud-trace-context": "2e5erfcc853dedff4c893b310dc0efdf/7061815258238150754;o=1",
  "x-client-data": "CgSL6ZyV",
  "traceparent": "00-2e5e4hcc853dedff4c893b310dc0efdf-62009b8ff0b7e862-01",
  "x-forwarded-for": "67.142.181.51",
  "x-forwarded-proto": "https",
  "forwarded": "for=\"67.142.181.51\";proto=https"
}

Other events besides Pub/Sub likely include some of these headers, or will in V2.

I'd assume that a CloudEvent signature would have something like:

function myFunction(cloudevent) {
  // The HTTP POST standard CloudEvent Headers
  // cloudevent.id
  // cloudevent.source
  // cloudevent.specversion
  // cloudevent.type
  // cloudevent.datacontenttype
  // cloudevent.dataschema
  // cloudevent.subject
  // cloudevent.time
  // cloudevent['x-cloud-trace-context']
  // cloudevent['user-agent']
  // cloudevent...
  // cloudevent.data // The HTTP POST body
}

Example HTTP headers:

{
  "host": "us-central1-project.cloudfunctions.net",
  "user-agent": "curl/7.64.1",
  "accept": "*/*",
  "forwarded": "for=\"67.143.181.51\";proto=https",
  "function-execution-id": "zve62c0a0o98",
  "traceparent": "00-100f0701fg2481493519e03f1d9d07d8-6111dfe1b4f54545-01",
  "x-appengine-city": "sf",
  "x-appengine-citylatlong": "36.851497,-16.171646",
  "x-appengine-country": "US",
  "x-appengine-default-version-hostname": "i89ff4052e6f73771p-tp.appspot.com",
  "x-appengine-https": "on",
  "x-appengine-region": "tx",
  "x-appengine-request-log-id": "60e77ea800ff02c0ebef425g4c0001737e6938396666343035326536633733373731702d7470000133626636363638333063373462396132616639623230643034336330333832393a3200010101",
  "x-appengine-timeout-ms": "599999",
  "x-appengine-user-ip": "67.123.181.51",
  "x-client-data": "CgSL6fsV",
  "x-cloud-trace-context": "103f0701f52481493519e03f1d9d07d8/6994617856779699525;o=1",
  "x-forwarded-for": "67.143.151.51",
  "x-forwarded-proto": "https",
  "connection": "close"
}

I assume we can just expose all of these headers to the function's first parameter. A user can decide which ones they care about. A CloudEvent

There should be no clash of cloudevent as none of these identifiers: "id", "source", "specversion", "type", "datacontenttype", "dataschema", "subject", "time" are HTTP headers.


We can also add this to the Event signature, though not really sure what interface we want.


(This raw HTTP request was captured using a custom Node Functions Framework)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions