# Additional http-headers with reply\_html\_page/2,3

**URL:** <https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624>\
**Category:** Help!\
**Created:** [February 19, 2021, 12:12pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624 "2021-02-19T12:12:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![remy.s](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@remy.s](https://swi-prolog.discourse.group/u/remy.s)\
**Post date:** [February 19, 2021, 12:12pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624/1 "2021-02-19T12:12:56Z")

</div>

Hello,  
I understand and use predicate “reply\_html\_page/2,3” to generate some html as a response to a http request.  
But besides the standard http headers (Content-Type, Content-Length), how can I add **additional http headers** to the response? E.g. If I wanted to add an [ETag](https://en.wikipedia.org/wiki/HTTP_ETag) to my response?  
Any ideas?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 19, 2021, 12:27pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624/2 "2021-02-19T12:27:00Z")

</div>

Just call this before reply\_html\_page/2. The task of the body is very similar to CGI scripts: it must write an HTTP header that ends with an empty line and then the body. So, any header you write before calling one of the page generation predicates is simply passed along.

```
format('Etag: ~w~n', [Etag])
```

---

<div class="post-metadata">

**Author:** ![remy.s](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@remy.s](https://swi-prolog.discourse.group/u/remy.s)\
**Post date:** [February 19, 2021, 12:34pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624/3 "2021-02-19T12:34:00Z")

</div>

Yep, this works, although I find the solution a bit “clumsy”

```prolog
format('x-header: ~w~n', [some])
, reply_html_page([title('Some title')], [h1('Some Title')]).

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 19, 2021, 12:37pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624/4 "2021-02-19T12:37:31Z")

</div>

I agree. Eventually there should be something like `http_add_header/2` that can be called anywhere during the body generation …

---

<div class="post-metadata">

**Author:** ![remy.s](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@remy.s](https://swi-prolog.discourse.group/u/remy.s)\
**Post date:** [February 19, 2021, 12:40pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624/5 "2021-02-19T12:40:21Z")

</div>

Agree, but looking at the code for reply\_html\_page/2,3, this doesn’t seem trivial to implement.  
Well, at least not by me…

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 19, 2021, 12:51pm UTC](https://swi-prolog.discourse.group/t/additional-http-headers-with-reply-html-page-2-3/3624/6 "2021-02-19T12:51:29Z")

</div>

It must be implemented in http\_wrapper.pl which formulates the final reply header (if my memory is accurate). I think we could maintain a global variable or thread-local dynamic predicate to contain the extra headers and inject these into the final reply header or something along these lines.
