001/* 002 * JKNIV, whinstone one contract to access your database. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.whinstone.couchdb; 021 022import org.apache.http.Header; 023import org.apache.http.client.methods.HttpRequestBase; 024import org.apache.http.message.BasicHeader; 025import org.apache.http.protocol.HTTP; 026 027public class RequestParams 028{ 029 private String connection; // Connection: keep-alive 030 private String cookieSession; // Cookie: AuthSession=YWRtaW46NUFCN0Y1Qzc6SQD7rM4vjA42_xp5ngAXYojGCEI 031 private String accept; // Accept: application/json, text/javascript, */*; q=0.01 032 private String contentType; // Content-Type: application/x-www-form-urlencoded; charset=UTF-8 033 private String schema; 034 //private long sessionTimeout; 035 036 public RequestParams(String schema) 037 { 038 super(); 039 this.connection = HTTP.CONN_KEEP_ALIVE; 040 //this.accept = "application/json"; 041 this.contentType = "application/json; charset=UTF-8"; 042 //this.sessionTimeout = TimeUnit.MINUTES.toSeconds(10L);// default cookie authentication timeout 043 //this.cookieSession = cookieSession; 044 } 045 046 public void setHeader(HttpRequestBase http) 047 { 048 if (connection != null) 049 http.addHeader("Connection", connection); 050 //if (cookieSession != null) 051 // http.addHeader("Cookie", cookieSession); 052 if (accept != null) 053 http.addHeader("Accept", accept); 054 if (contentType != null) 055 http.addHeader(HTTP.CONTENT_TYPE, contentType); 056 } 057 058 public void setConnection(String connection) 059 { 060 this.connection = connection; 061 } 062 063 public Header getConnection() 064 { 065 return new BasicHeader("Connection", connection); 066 } 067 068 069 public void setCookie(String cookie) 070 { 071 this.cookieSession = cookie; 072 } 073 074 public Header getCookie() 075 { 076 return new BasicHeader("Cookie", cookieSession); 077 } 078 079 080 public void setAccept(String accept) 081 { 082 this.accept = accept; 083 } 084 085 public Header getAccept() 086 { 087 return new BasicHeader("Accept", accept); 088 } 089 090 public void setContentType(String contentType) 091 { 092 this.contentType = contentType; 093 } 094 095 public Header getContentType() 096 { 097 return new BasicHeader(HTTP.CONTENT_TYPE, contentType); 098 } 099}