You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Michael Parker <mi...@gmail.com> on 2012/03/29 22:40:32 UTC

Referer header required for POST requests?

Hi all,

I'm writing a load test tool for CouchDB (coming soon, will be open
sourced, will announce it here, yada yada :) and when trying to insert
a document with a HTTP request like so:

POST /test_db/10 HTTP/1.1
Connection: keep-alive
Content-Type: application/json
Content-Length: 168

I get the reply:

{"error":"bad_request","reason":"Referer header required."}

Why is the referrer header required? Furthermore, for a standalone
tool like this, what's an appropriate value? I couldn't find any
mention of this header at
http://wiki.apache.org/couchdb/HTTP_Document_API#POST. I'm using Couch
1.1.1.

Thanks,
Mike

Re: Referer header required for POST requests?

Posted by Jens Alfke <je...@couchbase.com>.
On Mar 30, 2012, at 10:33 AM, Michael Parker wrote:

Oops, I was equating POST with creating a new document and PUT with
updating one. I didn't realize that PUT should always be used when
specifying a document URL. That works.

In a typical REST API, POST creates a new resource but lets the server decide what its URL will be. The URL of the request is usually the 'container' or parent of where the resource should go. By contrast, a PUT request can either create or update a resource, but the URL is always the resource itself.

—Jens

Re: Referer header required for POST requests?

Posted by Michael Parker <mi...@gmail.com>.
Oops, I was equating POST with creating a new document and PUT with
updating one. I didn't realize that PUT should always be used when
specifying a document URL. That works.

Thanks for your help!

- Mike


On Fri, Mar 30, 2012 at 9:42 AM, Jens Alfke <je...@couchbase.com> wrote:
>
> On Mar 29, 2012, at 1:40 PM, Michael Parker wrote:
>
> POST /test_db/10 HTTP/1.1
> Connection: keep-alive
> Content-Type: application/json
> Content-Length: 168
>
> I get the reply:
>
> {"error":"bad_request","reason":"Referer header required."}
>
> You're sending POST to a document URL, which as far as I know isn't valid.
> Did you mean to use PUT? Or to POST to /test_db ?
>
> —Jens

Re: Referer header required for POST requests?

Posted by Jens Alfke <je...@couchbase.com>.
On Mar 29, 2012, at 1:40 PM, Michael Parker wrote:

POST /test_db/10 HTTP/1.1
Connection: keep-alive
Content-Type: application/json
Content-Length: 168

I get the reply:

{"error":"bad_request","reason":"Referer header required."}

You're sending POST to a document URL, which as far as I know isn't valid.
Did you mean to use PUT? Or to POST to /test_db ?

—Jens

Re: Referer header required for POST requests?

Posted by Michael Parker <mi...@gmail.com>.
So I put a "foo.org" value there, and got the message "Referer header
must match host." Reading up, Host is a required field for HTTP 1.1,
but the bulk insert API with HTTP 1.1 actually works fine without it.

So I mapped foo.org to localhost in my hosts file, and for this request:

POST /test_db/10 HTTP/1.1
Connection: keep-alive
Content-Type: application/json
Host: foo.org
Referer: foo.org
Content-Length: 198

I still see the response:

{"error":"bad_request","reason":"Referer header must match host."}

I'm probably misunderstanding how the hosts file works or would help,
or I'm misunderstanding the error reason. Any help would be greatly
appreciated!

Thanks,
Mike


On Thu, Mar 29, 2012 at 1:47 PM, Robert Newson <rn...@apache.org> wrote:
> I believe it's a security thing, to stop cross-posting.
>
> On 29 March 2012 21:40, Michael Parker <mi...@gmail.com> wrote:
>> Hi all,
>>
>> I'm writing a load test tool for CouchDB (coming soon, will be open
>> sourced, will announce it here, yada yada :) and when trying to insert
>> a document with a HTTP request like so:
>>
>> POST /test_db/10 HTTP/1.1
>> Connection: keep-alive
>> Content-Type: application/json
>> Content-Length: 168
>>
>> I get the reply:
>>
>> {"error":"bad_request","reason":"Referer header required."}
>>
>> Why is the referrer header required? Furthermore, for a standalone
>> tool like this, what's an appropriate value? I couldn't find any
>> mention of this header at
>> http://wiki.apache.org/couchdb/HTTP_Document_API#POST. I'm using Couch
>> 1.1.1.
>>
>> Thanks,
>> Mike

Re: Referer header required for POST requests?

Posted by Robert Newson <rn...@apache.org>.
I believe it's a security thing, to stop cross-posting.

On 29 March 2012 21:40, Michael Parker <mi...@gmail.com> wrote:
> Hi all,
>
> I'm writing a load test tool for CouchDB (coming soon, will be open
> sourced, will announce it here, yada yada :) and when trying to insert
> a document with a HTTP request like so:
>
> POST /test_db/10 HTTP/1.1
> Connection: keep-alive
> Content-Type: application/json
> Content-Length: 168
>
> I get the reply:
>
> {"error":"bad_request","reason":"Referer header required."}
>
> Why is the referrer header required? Furthermore, for a standalone
> tool like this, what's an appropriate value? I couldn't find any
> mention of this header at
> http://wiki.apache.org/couchdb/HTTP_Document_API#POST. I'm using Couch
> 1.1.1.
>
> Thanks,
> Mike