# SSO avatar sync not working due to incorrect HTTP HEAD response

**URL:** https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979
**Category:** SSO
**Created:** [2017年十一月28日 21:29 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979 "2017-11-28T21:29:00Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Dany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dany/32/120447_2.png) [@Dany](https://meta.discourse.org/u/Dany)
#### Post date: [2017年十一月28日 21:29 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/1 "2017-11-28T21:29:00Z")

</div>

My main website is connected to my discourse application with SSO activated. Evrything work fine but the avatar syncing between website discourse.

I read all the thread about this and didn’t find any solution. I have configured “sso overrides avatar” and set avatar\_force\_update to true.

Here is the weired thing. First of all both my website and discourse are public with public ip / DNS etc not on localhost dev.

When the avatar url is hosted on any other website then mine then the avatar is uploaded / synced without any problem. So my integration code (SSO) is working.

When the avatar url is sent from my own website even if it is the same image that worked just before on another host then the sync just don’t work and the avatar don’t change.

So i think there is something special with my host (Nginx). Maybe the nginx gzip http reponse or something else ? I spend already 4 days trying to find an explanation without success and without any error message in avatar logs with sso logs activated that’s why i am here now.

The only Thread i found which seems to have the same problem is : [Cannot load avatar images from particular sites](https://meta.discourse.org/t/cannot-load-avatar-images-from-particular-sites/71003) but without any solution.

Any help would be apreciated.

Thanks !

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2017年十一月28日 22:02 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/2 "2017-11-28T22:02:20Z")

</div>

Any ideas here @sam or @tgxworld? Things to look for?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2017年十一月29日 03:25 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/3 "2017-11-29T03:25:40Z")

</div>

Anything in `/logs`? Our [URL resolver](https://github.com/discourse/discourse/blob/master/lib/final_destination.rb) has had problems recently downloading from certain URLs.

---

<div class="post-metadata">

### Author: ![Dany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dany/32/120447_2.png) [@Dany](https://meta.discourse.org/u/Dany)
#### Post date: [2017年十一月29日 05:06 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/4 "2017-11-29T05:06:20Z")

</div>

There is not any exceptions / error in logs files. If needed i can send you an avatar URL in private in order to let you test.  
You just have to force my avatar url in your SSO and voilà !

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2017年十一月29日 06:15 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/5 "2017-11-29T06:15:11Z")

</div>

Sure can you PM me the URL so that I can test it out?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2017年十一月30日 04:48 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/6 "2017-11-30T04:48:01Z")

</div>

Hmm this is odd, nginx on your site throws `404` when responding to a `HEAD` request.

```plaintext
$ curl --head <url>
HTTP/1.1 404 Not Found
Server: nginx/1.12.0
Date: Thu, 30 Nov 2017 04:44:41 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 9
Connection: keep-alive
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Thu, 01 Jan 1970 00:00:00 GMT

```

---

<div class="post-metadata">

### Author: ![Dany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dany/32/120447_2.png) [@Dany](https://meta.discourse.org/u/Dany)
#### Post date: [2017年十一月30日 15:14 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/7 "2017-11-30T15:14:05Z")

</div>

Yeah i didn’t implemented the HEAD http method because i don’t need it. Is this the cause of the bug ? If yes then why do you make a head request before getting the image because the head is already send with GET.

---

<div class="post-metadata">

### Author: ![Dany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dany/32/120447_2.png) [@Dany](https://meta.discourse.org/u/Dany)
#### Post date: [2017年十一月30日 21:21 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/8 "2017-11-30T21:21:33Z")

</div>

Ok i patched my code to answer to HEAD request and now it is working.  
You should mention that somewhere in the SSO doc 😓. You can’t imagine how many thread i found having problem with [discourse SSO](https://meta.discourse.org/t/13045?silent=true) avatars.

Thanks for your help 👍

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2017年十一月30日 21:30 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/9 "2017-11-30T21:30:20Z")

</div>

> [@Dany](#):
>
> Yeah i didn’t implemented the HEAD http method because i don’t need it.

> [@Dany](#):
>
> You should mention that somewhere in the SSO doc

Just checking: so you didn’t implement an important part of the HTTP specification and you think it’s the fault of the documentation of another system?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年十一月30日 21:34 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/10 "2017-11-30T21:34:46Z")

</div>

Note for future ref, the correct way of not implementing HEAD is by returning a [405 Method Not Allowed](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405)

---

<div class="post-metadata">

### Author: ![Dany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dany/32/120447_2.png) [@Dany](https://meta.discourse.org/u/Dany)
#### Post date: [2017年十一月30日 22:55 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/11 "2017-11-30T22:55:10Z")

</div>

I opened an issue on the framework i use in order to get more info about the default framework answer for non existing HTTP request.

I am, like most of web developpers, using a web framework. My web framework let me define each HTTP method separatly. Listening to you for each GET request i should implement his HEAD request equivalent ? (i am not making irony here it is a real question…)

@RGJ maybe you are right about the fact that “i didn’t implement an important part of the HTTP specification”. But i still think this should be mentionned somewhere in the doc or at least throw an error. [Discourse SSO](https://meta.discourse.org/t/13045?silent=true) can’t make a “hidden head request” get an error and not write anything in logs.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2017年十二月1日 06:46 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/12 "2017-12-01T06:46:52Z")

</div>

> [@Dany](#):
>
> My web framework let me define each HTTP method separatly. Listening to you for each GET request i should implement his HEAD request equivalent ?

I have never seen a modern framework which does not handle HEAD requests transparently as soon as you define a GET request… Which framework are you using?

> [@Dany](#):
>
> But i still think this should be mentionned somewhere in the doc or at least throw an error.

The idea behind a protocol specification is that docs are not cluttered with all kinds of details. Deviations of the specification should be mentioned, but it’s impossible to document where something _relies_ on the specification. If your framework indeed does not handle HEAD requests, then _that_ would be the place where it should be documented.

I do agree with you that throwing or logging an error would have been very helpful.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2017年十二月1日 07:04 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/13 "2017-12-01T07:04:27Z")

</div>

Why would you even disable HTTP HEAD? This is pointless. All you did is create extra work for yourself, and for us in replying to you.

---

<div class="post-metadata">

### Author: ![Dany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dany/32/120447_2.png) [@Dany](https://meta.discourse.org/u/Dany)
#### Post date: [2017年十二月1日 12:47 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/14 "2017-12-01T12:47:57Z")

</div>

@RGJ i am using a java framework called ninjaframework. I agree with you about everything dude i just never used HEAD request before because i never had to use it yet. My framework handle HEAD request but not automatically that’s the problem and many other framework doesn’t neither. But still, an error in logs should be welcome and as i told you i am not the only one facing this problem.

@codinghorror i didn’t disabled it, i just didn’t implemented it and the framework i use don’t do it automatically. Actually the only solution i get is that for each GET request i should clone it to HEAD request equivalent and spam my routing file with Head equivalent for all my GET methods. And that’s really ugly. I just did it for my assets folder in order to making avatar syncing work. I also don’t consider all this talking being a wast of time. This will help many people to do things the right way.

I also opened an issue and you guys are welcome : [HTTP head philosophy · Issue #592 · ninjaframework/ninja · GitHub](https://github.com/ninjaframework/ninja/issues/592)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2017年十二月1日 22:51 UTC](https://meta.discourse.org/t/sso-avatar-sync-not-working-due-to-incorrect-http-head-response/74979/15 "2017-12-01T22:51:27Z")

</div>


