How to minimise headers in URLRequest? Alternatives?

We're developing a connectivity library for IoT devices. It should support uploading (chunks of) firmware images to an IoT device over Wi-Fi.

To implement this feature we are performing "PUT" requests to an embedded HTTP server using URLRequest, but we noticed that the URL Loading System automatically inserts several HTTP header fields that the IoT device does not care about. Since this particular device has a very small buffer having a large header means there's not much space left for data (a chunk of the firmware image).

How can we minimise the headers of a request?

Or, what technology should we be using instead? (While still using the embedded HTTP server of the IoT device)
Which specific headers are you concerned about?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Examples of fields not required by the embedded HTTP server on the IoT device:
  • Accept-Language

  • User-Agent

In fact, we (probably) only need these two header fields in a request:
  • Authorization

  • Content-Length

Several posts on Stack Overflow show how to remove the value, but the buffer is so small that we want/need to remove the entire key/value pair (not just the value).

How would we achieve that?
I don’t think there’s any way to do this within URLSession. Our HTTP stack was designed for talking with general Internet servers and these headers aren’t a problem there.

I have a couple of suggestions for you:
  • You could avoid using an HTTP at all, instead use Network framework to run the TCP connection and CFHTTPMessage to form the request and parse the response. Normally I strongly recommend against this approach but, given the constraints of the accessory you’re talking to, it’s unlikely to cause problems (I can’t imagine it sending you a chunked response, for example).

  • You could use a third-party HTTP library (perhaps cURL). These are generally less opinionated than URLSession.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
How to minimise headers in URLRequest? Alternatives?
 
 
Q