Skip to content

Commit decc47f

Browse files
author
YOLANDA
committed
Stable version of 1.0.0
1 parent 1576c81 commit decc47f

File tree

106 files changed

+886
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+886
-608
lines changed

Jar/nohttp1.0.0.jar

101 Bytes
Binary file not shown.

nohttp/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ task sourcesJar(type: Jar) {
6969
task javadoc(type: Javadoc) {
7070
source = android.sourceSets.main.java.srcDirs
7171
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
72+
// destinationDir = file("../javadoc/")
73+
failOnError false
7274
}
7375
task javadocJar(type: Jar, dependsOn: javadoc) {
7476
classifier = 'javadoc'

nohttp/src/main/java/com/yolanda/nohttp/BasicConnection.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
import android.text.TextUtils;
4040

4141
/**
42-
* Package good Http implementation class, establish connection, read and write data
43-
* </br>
42+
* <p>Package good Http implementation class, establish connection, read and write data</p>
4443
* Created in Aug 4, 2015 10:12:38 AM
4544
*
4645
* @author YOLANDA
@@ -118,9 +117,9 @@ private void setHeaders(URI uri, HttpURLConnection connection, ImplServerRequest
118117
if (!TextUtils.isEmpty(acceptCharset))
119118
headers.set(Headers.HEAD_KEY_ACCEPT_CHARSET, acceptCharset);
120119

121-
String acceptLanguget = request.getAcceptLanguage();
122-
if (!TextUtils.isEmpty(acceptLanguget))
123-
headers.set(Headers.HEAD_KEY_ACCEPT_LANGUAGE, acceptLanguget);
120+
String acceptLanguage = request.getAcceptLanguage();
121+
if (!TextUtils.isEmpty(acceptLanguage))
122+
headers.set(Headers.HEAD_KEY_ACCEPT_LANGUAGE, acceptLanguage);
124123

125124
// 2.2 Connection
126125
// To fix bug: accidental EOFException before API 19
@@ -200,7 +199,7 @@ protected Headers parseResponseHeaders(URI uri, int responseCode, String respons
200199
*/
201200
private void writeRequestBody(HttpURLConnection connection, ImplServerRequest request) throws IOException {
202201
if (request.doOutPut()) {
203-
Logger.i("-------Send reqeust data start-------");
202+
Logger.i("-------Send request data start-------");
204203
BufferedOutputStream outputStream = new BufferedOutputStream(connection.getOutputStream());
205204
Writer writer = new Writer(outputStream, true);
206205
request.onWriteRequestBody(writer);

nohttp/src/main/java/com/yolanda/nohttp/BasicRequest.java

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
package com.yolanda.nohttp;
1717

18+
import android.text.TextUtils;
19+
20+
import com.yolanda.nohttp.tools.CounterOutputStream;
21+
import com.yolanda.nohttp.tools.Writer;
22+
1823
import java.io.IOException;
1924
import java.io.UnsupportedEncodingException;
2025
import java.net.Proxy;
@@ -25,14 +30,8 @@
2530
import javax.net.ssl.HostnameVerifier;
2631
import javax.net.ssl.SSLSocketFactory;
2732

28-
import com.yolanda.nohttp.tools.CounterOutputStream;
29-
import com.yolanda.nohttp.tools.Writer;
30-
31-
import android.text.TextUtils;
32-
3333
/**
34-
* Implement all the methods of the base class {@link ImplServerRequest} and {@link ImplClientRequest}
35-
* </br>
34+
* <p>Implement all the methods of the base class {@link ImplServerRequest} and {@link ImplClientRequest}</p>
3635
* Created in Nov 4, 2015 8:28:50 AM
3736
*
3837
* @author YOLANDA
@@ -69,6 +68,14 @@ public abstract class BasicRequest<T> implements Request<T> {
6968
* Cache key
7069
*/
7170
private String mCacheKey;
71+
/**
72+
* If just read from cache
73+
*/
74+
private boolean isOnlyReadCache;
75+
/**
76+
* If the request fails the data read from the cache
77+
*/
78+
private boolean isRequestFailedReadCache = false;
7279
/**
7380
* Proxy server
7481
*/
@@ -192,6 +199,26 @@ public String getCacheKey() {
192199
return TextUtils.isEmpty(mCacheKey) ? buildUrl() : mCacheKey;
193200
}
194201

202+
@Override
203+
public void setOnlyReadCache(boolean onlyReadCache) {
204+
this.isOnlyReadCache = onlyReadCache;
205+
}
206+
207+
@Override
208+
public boolean onlyReadCache() {
209+
return isOnlyReadCache;
210+
}
211+
212+
@Override
213+
public void setRequestFailedReadCache(boolean isEnable) {
214+
this.isRequestFailedReadCache = isEnable;
215+
}
216+
217+
@Override
218+
public boolean isRequestFailedReadCache() {
219+
return isRequestFailedReadCache;
220+
}
221+
195222
@Override
196223
public void setProxy(Proxy proxy) {
197224
this.mProxy = proxy;
@@ -531,14 +558,6 @@ public void toggleFinish() {
531558
this.isFinished = !isFinished;
532559
}
533560

534-
/**
535-
* @deprecated @deprecated Please use {@link #cancel(boolean)} instead
536-
*/
537-
@Override
538-
public void cancel() {
539-
cancel(true);
540-
}
541-
542561
@Override
543562
public void cancel(boolean cancel) {
544563
this.isCanceled = cancel;

nohttp/src/main/java/com/yolanda/nohttp/Binary.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
import com.yolanda.nohttp.able.CancelAble;
2121

2222
/**
23-
* File interface</br>
24-
* All the methods are called in Son thread.</br>
25-
* </br>
23+
* <p>File interface.
24+
* All the methods are called in Son thread.</p>
2625
* Created in Oct 12, 2015 4:44:07 PM
2726
*
2827
* @author YOLANDA
@@ -31,21 +30,29 @@ public interface Binary extends CancelAble {
3130

3231
/**
3332
* Length of byteArray
33+
*
34+
* @return Long length
3435
*/
3536
long getLength();
3637

3738
/**
3839
* Write your Binary data through flow out
40+
*
41+
* @param outputStream OutputStream
3942
*/
4043
void onWriteBinary(OutputStream outputStream);
4144

4245
/**
4346
* Return the fileName, Can be null
47+
*
48+
* @return File name
4449
*/
4550
String getFileName();
4651

4752
/**
4853
* Return mimeType of binary
54+
*
55+
* @return MimeType
4956
*/
5057
String getMimeType();
5158
}

nohttp/src/main/java/com/yolanda/nohttp/FileBinary.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import android.text.TextUtils;
2828

2929
/**
30-
* A default implementation of Binary</br>
31-
* All the methods are called in Son thread.</br>
32-
* </br>
30+
* <p>A default implementation of Binary.
31+
* All the methods are called in Son thread.</p>
3332
* Created in Oct 17, 2015 12:40:54 PM
3433
*
3534
* @author YOLANDA
@@ -123,14 +122,6 @@ public String getMimeType() {
123122
return mimeType;
124123
}
125124

126-
/**
127-
* @deprecated @deprecated Please use {@link #cancel(boolean)} instead
128-
*/
129-
@Override
130-
public void cancel() {
131-
this.isRun = false;
132-
}
133-
134125
@Override
135126
public void cancel(boolean cancel) {
136127
this.isRun = cancel;

nohttp/src/main/java/com/yolanda/nohttp/Headers.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import com.yolanda.nohttp.tools.MultiValueMap;
2828

2929
/**
30-
* Http header
31-
* </br>
30+
* <p>Http header</p>
3231
* Created in Jan 10, 2016 2:29:42 PM
3332
*
3433
* @author YOLANDA
@@ -69,7 +68,7 @@ public interface Headers extends MultiValueMap<String, String> {
6968

7069
String HEAD_KEY_EXPIRES = "Expires";
7170

72-
String HEAD_KEY_ETAG = "ETag";
71+
String HEAD_KEY_E_TAG = "ETag";
7372

7473
String HEAD_KEY_PRAGMA = "Pragma";
7574

@@ -93,18 +92,22 @@ public interface Headers extends MultiValueMap<String, String> {
9392

9493
/**
9594
* Copy all head to Headers
95+
*
96+
* @param headers Headers
9697
*/
9798
void addAll(Headers headers);
9899

99100
/**
100101
* Remove all of the head now, add a new head in
102+
*
103+
* @param headers headers
101104
*/
102105
void setAll(Headers headers);
103106

104107
/**
105108
* Conform to the URI of the Cookie is added to the head
106109
*
107-
* @param uri url
110+
* @param uri url
108111
* @param cookieHandler cookieHandler
109112
* @throws IOException When reading a Cookie from CookieHandler may be exception
110113
*/
@@ -120,76 +123,106 @@ public interface Headers extends MultiValueMap<String, String> {
120123

121124
/**
122125
* Into a json format string
126+
*
127+
* @return Json format data
123128
*/
124129
String toJSONString();
125130

126131
/**
127132
* Into a single key-value map
133+
*
134+
* @return Map
128135
*/
129136
Map<String, String> toRequestHeaders();
130137

131138
/**
132139
* To multiple key - the value of the map
140+
*
141+
* @return Map format data
133142
*/
134143
Map<String, List<String>> toResponseHeaders();
135144

136145
/**
137146
* All the cookies in header information
147+
*
148+
* @return {@code List<Cookie>}
138149
*/
139150
List<HttpCookie> getCookies();
140151

141152
/**
142153
* {@value #HEAD_KEY_CACHE_CONTROL}
154+
*
155+
* @return CacheControl
143156
*/
144157
String getCacheControl();
145158

146159
/**
147160
* {@value #HEAD_KEY_CONTENT_ENCODING}
161+
*
162+
* @return ContentEncoding
148163
*/
149164
String getContentEncoding();
150165

151166
/**
152167
* {@value #HEAD_KEY_CONTENT_LENGTH}
168+
*
169+
* @return ContentLength
153170
*/
154171
int getContentLength();
155172

156173
/**
157174
* {@value #HEAD_KEY_CONTENT_TYPE}
175+
*
176+
* @return ContentType
158177
*/
159178
String getContentType();
160179

161180
/**
162181
* {@value #HEAD_KEY_DATE}
182+
*
183+
* @return Date
163184
*/
164185
long getDate();
165186

166187
/**
167-
* {@value #HEAD_KEY_ETAG}
188+
* {@value #HEAD_KEY_E_TAG}
189+
*
190+
* @return ETag
168191
*/
169192
String getETag();
170193

171194
/**
172195
* {@value #HEAD_KEY_EXPIRES}
196+
*
197+
* @return Expiration
173198
*/
174199
long getExpiration();
175200

176201
/**
177202
* {@value #HEAD_KEY_LAST_MODIFIED}
203+
*
204+
* @return LastModified
178205
*/
179206
long getLastModified();
180207

181208
/**
182209
* {@value #HEAD_KEY_LOCATION}
210+
*
211+
* @return Location
183212
*/
184213
String getLocation();
185214

186215
/**
187216
* {@value #HEAD_KEY_RESPONSE_CODE}
217+
*
218+
* @return ResponseCode
188219
*/
189220
int getResponseCode();
190221

191222
/**
192223
* {@value #HEAD_KEY_RESPONSE_MESSAGE}
224+
*
225+
* @throws ResponseMessage
193226
*/
194227
String getResponseMessage();
195228
}

nohttp/src/main/java/com/yolanda/nohttp/HttpHeaders.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import android.text.TextUtils;
3939

4040
/**
41-
* {@link Headers} The default implementation
42-
* </br>
41+
* <p>{@link Headers} The default implementation</p>
4342
* Created in Jan 10, 2016 2:37:06 PM
4443
*
4544
* @author YOLANDA
@@ -190,7 +189,7 @@ public long getDate() {
190189

191190
@Override
192191
public String getETag() {
193-
return getValue(HEAD_KEY_ETAG, 0);
192+
return getValue(HEAD_KEY_E_TAG, 0);
194193
}
195194

196195
@Override

nohttp/src/main/java/com/yolanda/nohttp/HttpResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
package com.yolanda.nohttp;
1717

1818
/**
19-
* </br>
2019
* Created in Jan 6, 2016 5:19:13 PM
2120
*
2221
* @author YOLANDA;
2322
*/
2423
public class HttpResponse {
2524

25+
public final boolean isFromCache;
2626
public final byte[] responseBody;
2727
public final Headers responseHeaders;
2828
public final Exception exception;
2929

30-
public HttpResponse(Headers responseHeaders, byte[] responseBody, Exception exception) {
30+
public HttpResponse(boolean isFromCache, Headers responseHeaders, byte[] responseBody, Exception exception) {
31+
this.isFromCache = isFromCache;
3132
this.responseHeaders = responseHeaders;
3233
this.responseBody = responseBody;
3334
this.exception = exception;

0 commit comments

Comments
 (0)