androidhttp-headersopenstreetmaposmdroid

How to add http header to requests made by OSMDroid?


I have my client's open street map tile server, which identificates client by checking cookie header sent with request. Here is a format:

Header:

Cookie: my_clients_company_cookie=0hPRvPfAK65TLASejXTtb6xjsRcH0D7t

Request:

https://fleet.my_clients_company.com/tile?z=10&x=610&y=510

Here is TileSource config I use:

val tileSource: ITileSource
    get() = object : OnlineTileSourceBase(
        "My Client's Company", // name
        3, // min zoom 
        18, // max zoom
        512, // tile size
        ".png",
        arrayOf("https://fleet.my_clients_company.com/tile")
    ) {

        override fun getTileURLString(pMapTileIndex: Long): String =
            "$baseUrl?z=${MapTileIndex.getZoom(pMapTileIndex)}&x=${MapTileIndex.getX(pMapTileIndex)}&y=${MapTileIndex.getY(pMapTileIndex)}"

    }

Without sending header, I get 401 Unauthorized error response. I haven't find a way to set headers. Is it possible without forking library?


Solution

  • If it is not possible to supply the cookie value as a normal GET parameter by appending to the URL (did you try this?), I believe you have to implement your own Tile Source.

    You can have a look at the BingMapTileSource which sets a UserAgent header, similarly you could set a cookie.