# Extra HTTP headers for \`file(UPLOAD|DOWNLOAD)\`

**URL:** https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152
**Category:** Development
**Created:** [May 6, 2020, 2:13am UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152 "2020-05-06T02:13:10Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![zaufi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zaufi/32/116_2.png) [@zaufi](https://discourse.cmake.org/u/zaufi)
#### Post date: [May 6, 2020, 2:13am UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/1 "2020-05-06T02:13:10Z")

</div>

Hi,

Sometimes doing HTTP operations it’s required to provide some extra headers. For example, talking to JFrog Artifactory requires the `X-JFrog-Art-Api` header w/ API key.

I propose to add `EXTRA_HEADERS <string>...` named parameter to the `file(UPLOAD|DOWNLOAD ...)` signature.

P.S. I’m ready to make an MR for this.

P.S.S. The other thing that will be nice to have is a configurable HTTP method to be able to talk to various REST APIs. For example, _upload_ could be done via `POST`, `PUT`, `CREATE`, or even `PATCH` methods. There is HTTP `DELETE` method which is also nice to have (e.g. to delete files from Artifactory repos), but currently I’ve got no clear idea how to extend `file` signature for this.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [May 6, 2020, 7:30am UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/2 "2020-05-06T07:30:25Z")

</div>

`file(DOWNLOAD)` and `file(UPLOAD)` support the `HTTPHEADER` keyword since CMake 3.7 (see [https://cmake.org/cmake/help/latest/release/3.7.html#commands](https://cmake.org/cmake/help/latest/release/3.7.html#commands)).

---

<div class="post-metadata">

### Author: ![zaufi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zaufi/32/116_2.png) [@zaufi](https://discourse.cmake.org/u/zaufi)
#### Post date: [May 6, 2020, 10:26am UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/3 "2020-05-06T10:26:40Z")

</div>

OMG! How can I miss it!? %)  
Great "news@ 2 me 🙂

---

<div class="post-metadata">

### Author: ![zaufi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zaufi/32/116_2.png) [@zaufi](https://discourse.cmake.org/u/zaufi)
#### Post date: [May 10, 2020, 6:21am UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/4 "2020-05-10T06:21:37Z")

</div>

Ugh ☹  
Unfortunately nor `file(DOWNLOAD)`neither `UPLOAD` can’t be used to talk to REST API of JFrog Artifactory ☹

I need to send some content and receive JSON response.

@brad.king, @craig.scott

I’d like to add a `http()` command for that purpose. What do you think?

```auto
http(
   GET|POST|PUT|CREATE|DELETE|... <url> 
   [CONTENT <string>] 
   [HTTPHEADERS <header>...]
   [TIMEOUT <seconds>]
   [RESULT_VARIABLE <name>]
   [ERROR_VARIABLE <name>]
 )

```

where the first parameter is a HTTP method (i.e., `GET`, `POST`, `PUT`, `CREATE` & etc).

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 11, 2020, 11:56am UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/5 "2020-05-11T11:56:21Z")

</div>

@zaufi you’ve been proposing many CMake language features that imply you’re using it as a general-purpose scripting language. Why? It’s meant for configuring project build trees and simple glue scripts. Interacting with REST APIs is well outside that scope. I don’t think we should grow the language that much.

One can use `find_program()/find_package(...)` and `execute_process` do arbitrary things in a true general-purpose language like Python.

---

<div class="post-metadata">

### Author: ![zaufi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zaufi/32/116_2.png) [@zaufi](https://discourse.cmake.org/u/zaufi)
#### Post date: [May 11, 2020, 12:07pm UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/6 "2020-05-11T12:07:09Z")

</div>

My case:  
I’ve added a custom target to build ABI dumps. The result dumps I want to store in JFrog Artifactory at the release build step. The master builds gonna check the ABI changes against the latest release.

Having “external” scripts in Python, means I have to start at lease one repo and full featured Python project which includes: tests, `setup.py`, building package, add CI builds, add a private `pypi` repo and deploy built packages to it, manage to preinstall of this CLI tool into my docker images used to build my projects, use `find_program` in my CMake project, add custom target or output…

All that pain in the ass could be done w/ couple REST API requests to Artifactory… ☹

That is why I strongly believe `http()` command is a better way.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [May 11, 2020, 12:34pm UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/7 "2020-05-11T12:34:23Z")

</div>

May be a tool like `curl` will match your needs… with a largely less complex infrastructure than `python`.

---

<div class="post-metadata">

### Author: ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)
#### Post date: [May 11, 2020, 1:04pm UTC](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152/8 "2020-05-11T13:04:48Z")

</div>

> [@zaufi](#):
>
> Having “external” scripts in Python, means I have to start at lease one repo and full featured Python project which includes: tests, `setup.py` , building package, add CI builds, add a private `pypi` repo and deploy built packages to it, manage to preinstall of this CLI tool into my docker images used to build my projects, use `find_program` in my CMake project, add custom target or output…

No sure why you say that.  
You can perfectly use a prebuilt python docker image (or any other prebuilt image that contains the tools you need to do REST request) and use it to run a python script which would be stored in your current repo as an helper script just as CMakeLists.txt or other xxx.cmake may be.  
I don’t get why you would need a full-blown python module for that?  
You may pass anything coming from a CMake build (CI) step as build artifact to the one that needs it.

I don’t know which CI you use but I bet any CI could use various docker images for various step/jobs?

Or may be I missed something in your points?
