Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read HTTP request headers, and modify response headers of an Apps Script web app

Can I modify the HTTP response headers to add cookies and extra information? Also I'm having troubles reading the request headers.

like image 613
Luca Matteis Avatar asked Dec 12 '12 20:12

Luca Matteis


People also ask

Can I read response headers in Javascript?

While you can't ready any headers of HTML response in JS, you can read Server-Timing header, and you can pass arbitrary key-value data through it.

Can HTTP headers be modified?

Modify Header Value (HTTP Headers) is an extension that can add, modify or remove an HTTP-request-header for all requests on a desired website or URL. This Addon is very useful if you are an App developer, website designer, or if you want to test a particular header for a request on a website.

What is HTTP request and response header?

An HTTP header is a field of an HTTP request or response that passes additional context and metadata about the request or response. For example, a request message can use headers to indicate it's preferred media formats, while a response can use header to indicate the media format of the returned body.


1 Answers

You cannot read or set HTTP Headers in a Apps Script app deployed as a web app. You are restricted to reading the query string or the post values for GET/POST respectively. When responding you can only return the content and the MIME type (restricted to a few types)

This is because the scripts are served off the Google.com domain and you should not have ways to set/get cookies that could potentially be used for malicious reasons.

However, if you are using UrlFetch within an Apps Script app to make outbound calls, you have much more control of the HTTP headers

like image 53
Arun Nagarajan Avatar answered Nov 15 '22 09:11

Arun Nagarajan