client: add lws_http_client_http_response api
diff --git a/lib/client.c b/lib/client.c
index 7731e8a..53c3929 100755
--- a/lib/client.c
+++ b/lib/client.c
@@ -387,6 +387,15 @@
 	return 0;
 }
 
+LWS_VISIBLE LWS_EXTERN unsigned int
+lws_http_client_http_response(struct lws *wsi)
+{
+	if (!wsi->u.http.ah)
+		return 0;
+
+	return wsi->u.http.ah->http_response;
+}
+
 int
 lws_client_interpret_server_handshake(struct lws *wsi)
 {
@@ -394,7 +403,7 @@
 	int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR;
 	struct lws_context *context = wsi->context;
 	const char *pc, *prot, *ads = NULL, *path, *cce = NULL;
-	struct allocated_headers *ah;
+	struct allocated_headers *ah = NULL;
 	char *p;
 #ifndef LWS_NO_EXTENSIONS
 	struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
@@ -415,6 +424,7 @@
 		lws_union_transition(wsi, LWSCM_HTTP_CLIENT_ACCEPTED);
 		wsi->state = LWSS_CLIENT_HTTP_ESTABLISHED;
 		wsi->u.http.ah = ah;
+		ah->http_response = 0;
 	}
 
 	/*
@@ -450,6 +460,9 @@
 		goto bail3;
 	}
 	n = atoi(p);
+	if (ah)
+		ah->http_response = n;
+
 	if (n == 301 || n == 302 || n == 303 || n == 307 || n == 308) {
 		p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_LOCATION);
 		if (!p) {
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
index d4f81de..4d33d59 100644
--- a/lib/libwebsockets.h
+++ b/lib/libwebsockets.h
@@ -2145,6 +2145,16 @@
 LWS_VISIBLE LWS_EXTERN int
 lws_http_client_read(struct lws *wsi, char **buf, int *len);
 
+/**
+ * lws_http_client_http_response() - get last HTTP response code
+ *
+ * \param wsi: client connection
+ *
+ * Returns the last server response code, eg, 200 for client http connections.
+ */
+LWS_VISIBLE LWS_EXTERN unsigned int
+lws_http_client_http_response(struct lws *wsi);
+
 LWS_VISIBLE LWS_EXTERN void
 lws_client_http_body_pending(struct lws *wsi, int something_left_to_send);
 
diff --git a/lib/parsers.c b/lib/parsers.c
index 5dfcc17..72e35dd 100644
--- a/lib/parsers.c
+++ b/lib/parsers.c
@@ -78,6 +78,7 @@
 	memset(ah->frag_index, 0, sizeof(ah->frag_index));
 	ah->nfrag = 0;
 	ah->pos = 0;
+	ah->http_response = 0;
 
 	/* since we will restart the ah, our new headers are not completed */
 	// wsi->hdr_parsing_completed = 0;
diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h
index a487a89..f4a5d5e 100644
--- a/lib/private-libwebsockets.h
+++ b/lib/private-libwebsockets.h
@@ -652,6 +652,8 @@
 	unsigned int rxlen;
 	unsigned int pos;
 
+	unsigned int http_response;
+
 #ifndef LWS_NO_CLIENT
 	char initial_handshake_hash_base64[30];
 #endif