Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

406 Not Acceptable with version 0.2.13 #1610

Closed
brgrz opened this issue Dec 5, 2014 · 19 comments
Closed

406 Not Acceptable with version 0.2.13 #1610

brgrz opened this issue Dec 5, 2014 · 19 comments

Comments

@brgrz
Copy link

brgrz commented Dec 5, 2014

I'm loading UI router from jsdelivr version 0.2.13 and I get 406 Not Acceptable on angular's

xhr.send(post || null);

The same goes for 0.2.12 but everything works fine with 0.2.11.

@christopherthielen
Copy link
Contributor

I have no idea what you're talking about

@brgrz
Copy link
Author

brgrz commented Dec 5, 2014

Well, the template from templateUrl doesn't get loaded because of the above error which happens within angular.js (line 9734).

this is my app.config

app.config(['$urlRouterProvider', '$stateProvider', '$locationProvider',
function ($urlRouterProvider, $stateProvider, $locationProvider) {

    // hashbangs
    $locationProvider.hashPrefix("!");

    // For any unmatched url, redirect to /
    $urlRouterProvider.otherwise("/");

    // Now set up the states
    $stateProvider.state('home', {
        url: "/",
        templateUrl: "src/app/home/home.html"
    });

    $stateProvider.state('stories/editor', {
        url: "/stories/editor",
        templateUrl: "src/app/stories/editor.html"
    });
}]);

The same app works fine with 0.2.11

@christopherthielen
Copy link
Contributor

Please be specific, I can't possibly guess what your environment is doing.

When UI-Router attempts to retrieve the template "src/app/home/home.html", then the HTTP server returns a HTTP 406 code?

@brgrz
Copy link
Author

brgrz commented Dec 5, 2014

exactly

@christopherthielen
Copy link
Contributor

sounds like your server is rejecting the HTTP request. As of 0.2.12 we are now requesting templates with an accept: text/html header. Why would your server reject that request?

#1341

@brgrz
Copy link
Author

brgrz commented Dec 5, 2014

hm, could be, if that's the change then probably that's it, let me check it out

@brgrz
Copy link
Author

brgrz commented Dec 5, 2014

Ok, it is the server configuration indeed. My server (IIS, IIS Express) is configured with this:

        <remove fileExtension=".html" />
        <mimeMap fileExtension=".html" mimeType="text/html; charset=UTF-8" />

So we're removing the .html extension and readding it modified. This actually came from H5BP web.config for IIS.

It started to work after commenting this out. It also works if I remove the charset specification in this rule.

Now the only question remains, who's got this right? Your without charset specification or H5BP's that specifies it?

@nateabele
Copy link
Contributor

Microsoft traditionally fucks up specifications, and we're not doing anything special with the charset. If this is a genuine problem for you, you can always compress your templates using any one of the available Angular toolsets to preload them into your page. Or, you can provide your own implementation of $templateFactory to override the built-in one.

@brgrz
Copy link
Author

brgrz commented Dec 6, 2014

Wow, now this is what you call a sublime response. Or simply ignorant.

I could reply with "there's OSS that traditionally doesn't give a fuck about i18n and there's OSS that actually cares about i18n".

This has nothing to do with Microsoft, it is H5BP community proven web.config setting based on W3C recommendations (http://www.w3.org/International/O-HTTP-charset), which, I should say, worked without problems so far and this is the first time I ran into it, so it is ui-router that does something special.

You might want to reconsider and set the accept header to something more sensible which "text/html; charset:utf-8" certainly is.

Unless you don't give a fuck about international charsets.

@nateabele
Copy link
Contributor

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html:

If no Accept-Charset header is present, the default is that any character set is acceptable. If an Accept-Charset header is present, and if the server cannot send a response which is acceptable according to the Accept-Charset header, then the server SHOULD send an error response with the 406 (not acceptable) status code, though the sending of an unacceptable response is also allowed.

Have a nice day.

@nateabele
Copy link
Contributor

You might want to reconsider and set the accept header to something more sensible which "text/html; charset:utf-8" certainly is.

Unless you don't give a fuck about international charsets.

Except that this would create problems for Thai and Korean, and (I believe) one or two Japanese character sets, which Unicode doesn't cover.

@brgrz
Copy link
Author

brgrz commented Dec 6, 2014

Where did you come up with that? UTF-8 covers everything and is regarded as the encoding of choice for HTML5 and whatnot. For sure you know that. By being multibyte encoding it can cover anything (Thai, Korean and Japanese are covered they just take more bytes to encode them).

btw H5BP's configs for apache set it to text/html; charset: utf-8 too.

Your objections start to sound more of a whim.

@brgrz
Copy link
Author

brgrz commented Dec 6, 2014

The most important thing is, I configure my server to return HTML files encoded with a character set that supports a wider range of characters (UTF-8) and you want me to turn that back to the setting that has way less characters covered (ISO-8859-1, which is the default).

And, by the way, using ui-router, can we even specify which charset should be used for XHR template loading?

@brgrz
Copy link
Author

brgrz commented Dec 6, 2014

#1614

@brutaldev
Copy link

Not going to get involved in the flame war here, just want to add my two cents.

I ran into the exact same issue thanks to web.config settings recommended by H5BP so thanks @brgrz for figuring that one out. I agree with @brgrz here as well that the charset should be sent since this seems to be the general recommendation out there. It's unlikely that the requested change will cause any problems for existing users, however, changing the header to one without a charset certainly does.

@rluiten
Copy link

rluiten commented Aug 19, 2015

I ran into this yesterday, I actually created a http interceptor that checked the url path for where our template html files live and modified the Accept header to */*. It is a hack but I thought some one else who ends up here after a search might find the information useful.

I did try to set the accept header to "text/html; charset=UTF-8" but that caused IIS to keep returning 406's unclear why. using "*/*" for our path checked url land ending in html did not seem to risky

@RichardM99
Copy link

I also ran into this issue guys so thanks to everyone in the thread for their contribution, really helped me out.

@Pharylon
Copy link

I put this inside my module's config:

.config(["$httpProvider",
 function($httpProvider) {

   $httpProvider.interceptors.push(function() {
     return {
       "request": function(config) {
         if (config.url && config.url.endsWith(".html")){
           config.headers["Content-Type"] = "text/html; charset=utf=8";
           config.headers["Accept"] = "text/html; charset=utf=8";
         }
         return config;
       }
     };
   });


 };

@drewfreyling
Copy link

This is also a problem in 0.2.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants