syffinx
syffinx

Reputation: 361

HTTP 307 redirect does not work in firefox

We have a custom webserver, written in C.

When the browser visits the page http://mydomain.com:30001/index.html,

our webserver will redirect the browser to mydomain.com:30001/login.html, by sending a http 307 response to the browser, then the browser will visit the login url.

This worked well in IE 8, and Chrome.

But in firefox(18+), when visiting the page http://mydomain.com:30001/index.html,

the browser cannot load the page(/index.html nor /login.html), and seems to be in the loading process forever. (And firebug > network panel shows nothing.)

I also tried firefox setting

Tools > Options > Advanced > General : Accessibility : [ ] "Warn me when web sites try to redirect or reload the page",

but has no effect and nothing changed.

So I wonder why firefox behaves different or there's other reason.

Update: here's firefox HTTP part captured in wireshark

1.REQUEST(when visiting http://mydomain.com:30001/index.html in the browser addressbar)

GET /index.html HTTP/1.1
Host: mydomain.com:30001
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive

2.RESPONSE

HTTP/1.1 307 Temporary Redirect
Connection: keep-alive
Location: /login.html

that's all, and firefox does not fetch /login.html with another request.

Upvotes: 0

Views: 4624

Answers (2)

syffinx
syffinx

Reputation: 361

By comparing responses from other servers, it looks like by adding

Content-Length: 0

in the response header solved the problem. Thanks.

According to the protocol, Content-Length can be determined by connection close if there's no Content-Length given.

My original response provides no Content-Length, means the browser is waiting the end of transfer of this response to know the right length, but setting Connection: keep-alive does not end this connection.

I guess IE or Chrome starts redirect processing right after it knows it's a 307 redirect, while firefox does not do so until it completes reading this response.

Upvotes: 4

Julian Reschke
Julian Reschke

Reputation: 42017

Here's a test case for 307 that works with Firefox: http://greenbytes.de/tech/tc/httpredirects/#t307loc. You'll have to find out what's different in your server.

Upvotes: 1

Related Questions